gpt4 book ai didi

c++ - mysql-namer.exe :0xC000005:Access Violation in reading location 0x00000000 中 0x51f99754 处出现未处理的异常

转载 作者:行者123 更新时间:2023-11-30 00:19:40 26 4
gpt4 key购买 nike

我在我的 C++ 程序中使用 mysql C API 来更新远程数据库并解析返回行数的选择查询。

这是我的代码:

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.

请帮忙。

最佳答案

您正在向数据库引擎不希望的地方传递 NULL 指针。

使用调试器获取回溯(调用堆栈) - 这将显示代码中的哪一行是“罪魁祸首”。

关于c++ - mysql-namer.exe :0xC000005:Access Violation in reading location 0x00000000 中 0x51f99754 处出现未处理的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23335245/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com