MYSQL总是返回失败
MYSQL Returns FAIL Always
这段用c++编写的代码查询MYSQL在线数据库。它似乎总是返回0。即使我知道答案应该是1及格。当它运行时,我没有得到错误。
if ( bShowTCP )
{
printf("n -------------------- // -------------------- ");
printf("n TCP Header:");
int *addressValue = new int();
char *address = LIP;
inet_pton(AF_INET, address, addressValue);
if (ip_header->source_ip == *addressValue)
{
printf("n Source IP: %s", "0.0.0.0");
printf("n Destination IP: %s", ipDest);
}
else
{
printf("n Source IP: %s", ipSrc);
printf("n Destination IP: %s", ipDest);
(mysql_real_connect
(conn,"<hostname>","<db>","<user>","<pass>",0,NULL,0) !=0);
(mysql_query(conn,"SELECT COUNT(*) FROM tblURLIP WHERE IP = 'ipSrc' And IPStatus = '1' And IPMax = '0'"));
my_ulonglong i = 0;
res_set = mysql_store_result(conn);
my_ulonglong numrows = mysql_num_rows(res_set);
LEGIT = mysql_fetch_row(res_set);
if (atoi(LEGIT[i]) == 1)
{
printf("n PASS: %sn",LEGIT[i]);
mysql_free_result(res_set);
}
else
{
printf("n FAIL! %sn",LEGIT[i]);
mysql_free_result(res_set);
}
}
}
没有变量被传递到你的MySQL查询- WHERE IP = 'ipSrc'
是字面上搜索行,其中IP
有值"ipSrc"
,而不是那些它等于字符串变量称为ipSrc
的值。您需要使用sprintf()
之类的函数将ipSrc
的值嵌入到字符串中,或者使用准备好的语句并将ipSrc
绑定到占位符变量。
相关文章:
- 函数返回时,带指针的复制构造函数失败
- 当命令失败时,gzip 会在 C++ 中返回错误代码吗?
- 测试用例状态为失败,但返回的值为 true
- 返回 std::stringstream - 编译失败
- VirtualAllocEx 失败 GetError 返回ERROR_INVALID_ADDRESS
- 在 Linux 上,JNI AttachNativeThread 总是失败,返回值为 -1
- 从返回绑定中获取函数失败
- GMock 的"WillOnce"和"Return"不会因错误的返回值而失败
- 失败RSA_Verify将返回错误的签名错误
- 函数应该返回可能会失败的功能
- 使用Outlook 2016:MAPISendMail在Windows应用程序中失败,并返回"MAPI_E_FAILURE"作为错误代码
- 返回 std::p air<const CustomClass &, bool> 用于搜索函数中的失败情况,当 CustomClass 是抽象基类时
- 为什么返回的 FILE* 在 popen() 中的命令失败时保留数据
- C++重写 void 函数返回类型会导致生成失败
- 查找函数在失败结果中应该返回什么
- 超能力 NDK 安卓:返回 int 在"extern"块中成功,在调用函数中失败
- 根据通过/失败返回,在MFC对话框中更改LED颜色
- PyImport_Import失败 - 返回 NULL
- fwrite 失败(返回 0,错误给出 "Bad address")
- 使用Visual Studio-commander配置Qt 4.7.3失败(返回#2)