我在c++程序中使用mysql来更新远程数据库,并解析返回行数的select查询。
下面是我的代码:
MYSQL *con = mysql_init(NULL);
if (con == NULL)
{
AfxMessageBox("Could not initialize SQL Connection");
return;
}
if (mysql_real_connect(con, LINK, UID, PASSWORD, NULL, 0, NULL, 0) == NULL)
{
AfxMessageBox("Could not connect to MySQL Server");
return;
}
sprintf(uquery, "UPDATE test SET `emailid` = '%s', `name` = '%s' WHERE `ID` IS NULL;", eID, name);
mysql_query(con, uquery);
sprintf(squery,"SELECT * FROM test WHERE `emailID` = '%s' AND `ID` IS NOT NULL", key, emailID);
mysql_query(con,squery);
MYSQL_RES *res = mysql_store_result(con);
if((int)mysql_num_rows(res) != NULL)//<--ERROR SHOWS HERE
{
int rows = mysql_num_rows(res);
if (rows == 1)
{
//Do something
}
else
{
//Do Something else
}
}
else
{
//Some function 3
}
mysql_free_result(res);
mysql_close(con);我收到以下错误:
Unhandled exception at 0x51f99754 in namer.exe: 0xC0000005: Access violation reading location 0x00000000.请帮帮忙。
发布于 2014-04-28 15:45:48
您正在将空指针传递到数据库引擎不期望的某个位置。
使用调试器获取回溯(调用堆栈)-这将显示代码中的哪一行是“罪魁祸首”。
https://stackoverflow.com/questions/23335245
复制相似问题