Knowledge Base Nr: 00152 mysql.cpp - http://www.swe-kaiser.de
Downloads:
Win32: MySQL Beispielcode für C++ (Visual Studio)
#pragma comment(lib, "libmySQL.lib")
//includepfad muss gesetzt sein
//ACHTUNG: socketsupport muss aktiviert sein
#include <mysql.h>
void CMysqltestDlg::OnButton1()
{
m_lb.ResetContent();
MYSQL *myData ;
MYSQL_RES *res ;
MYSQL_ROW row ;
myData = mysql_init((MYSQL*) 0);
if (!myData)
return;
if (!mysql_real_connect(myData, "192.168.32.70", "admin", "xxx", "test"
, MYSQL_PORT, NULL, 0 ))
{
mysql_close(myData) ;
return;
}
if (mysql_select_db(myData, "test") < 0)
{
mysql_close(myData) ;
return;
}
//....
if (mysql_query(myData, "SELECT * FROM mydummy2"))
{
mysql_close(myData);
return;
}
res = mysql_store_result(myData);
while (row = mysql_fetch_row(res))
{
int nCount = mysql_num_fields(res) ;
CString str;
for (int k=0; k<nCount; k++)
{
str += (char*)row[k];
str += "#";
}
m_lb.AddString(str);
}
mysql_free_result(res);
mysql_close( myData ) ;
}