在数据库中插入C++ MySQL
这是我的代码,我试图在数据库中的sma中插入ma,但出现以下错误: 函数“int mysql\u queryMYSQL*,const char*”的参数太多 注释在mysql.h中声明 h中的行:int STDCALL mysql_queryMYSQL*mysql,const char*q在数据库中插入C++ MySQL,c++,mysql,C++,Mysql,这是我的代码,我试图在数据库中的sma中插入ma,但出现以下错误: 函数“int mysql\u queryMYSQL*,const char*”的参数太多 注释在mysql.h中声明 h中的行:int STDCALL mysql_queryMYSQL*mysql,const char*q while(true) { mysql_query(conn, " select close, id from fivemin order by id DESC LIMIT 5 ");
while(true)
{
mysql_query(conn, " select close, id from fivemin order by id DESC LIMIT 5 ");
result = mysql_store_result(conn);
num_fields = mysql_num_fields(result);
float sum = 0;
while((row=mysql_fetch_row(result)))
{
sum += atof(row[0]);
last_id = atoi(row[1]);
}
float ma;
ma=sum/5.0;
if(previous_last_id != last_id)
{
cout << "Simple moving Average: " << ma << endl;
previous_last_id = last_id;
}
mysql_query(conn,("insert into sma values('%f')"),ma);
Sleep(1000);
}
mysql\u queryconn,插入sma值“%f”,ma有三个参数
在调用mysql\u查询之前,需要格式化字符串
例如:
char str[80];
sprintf(str, "insert into sma values('%f')", ma);
mysql_query(conn, str);
这里使用的是C连接器。对于C++,有。包括头吗?乐意帮助,欢迎使用堆栈溢出。如果此答案解决了您的问题,请将其标记为已接受。