c++ - Mysql.h C++ 参数过多

标签 c++ mysql linux

现在,当我编译时,我收到:

/usr/include/mysql/mysql.h:452: error: too many arguments to function int mysql_query(MYSQL*, const char*)

mysql.h 的参数是否有限制?如果有,我该如何解决它?

#include    <mysql/mysql.h>


string unknown = "Unknown";

MYSQL *conn;

conn = mysql_init(NULL);
mysql_real_connect(conn, "localhost", "root", "password", "alert", 0, NULL, 0);

mysql_query(conn, "INSERT INTO alert_tbl (alert_srcip, alert_country, alert_destip, alert_desthost, alert_destport, alert_bl) VALUES ('%s','%s','%s','%s','%s','%s')", src_ip,country_code,dest_ip,unknown,dest_prt,blip);

mysql_close(conn);

g++ test.c -o test -lstdc++ -I/usr/include/mysql -L/usr/lib/mysql -lmysqlclient

最佳答案

您必须使用mysql_stmt_prepare然后使用 mysql_stmt_bind_param 将参数值一一绑定(bind)

当语句准备好后,使用 mysql_stmt_execute 执行它

或者使用 sprintf():

char query[1024 /* or longer */];

sprintf(query,
     "INSERT INTO alert_tbl"
     "(alert_srcip, alert_country, alert_destip, alert_desthost, alert_destport, "
     "alert_bl) VALUES ('%s','%s','%s','%s','%s','%s')",
     src_ip,country_code,dest_ip,unknown,dest_prt,blip);

mysql_query(conn, query);

关于c++ - Mysql.h C++ 参数过多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11263634/

相关文章:

linux - Crontab 权限被拒绝

c++ - 使用 UTF-8 在非 ASCII 字符上运行 Ascii 正则表达式

c++ - 有符号的十六进制文字可能吗?

c++ - while循环中的浮点比较与模数

C++ 将八个 boolean 值压缩为一个字符

MySql安装数据库初始化报错

python - 在没有 root 的情况下安装 Python 2.7

MySQL 触发器 - 触发器表名称解释为字段

php - 关于通过 php 使用 ezpdf 将数据从 mysql 导出到 pdf 的 undefined variable session

c++ - new分配了多少字节?