现在,当我编译时,我收到:
/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/