Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/157.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在数据库中插入C++ MySQL_C++_Mysql - Fatal编程技术网

在数据库中插入C++ MySQL

在数据库中插入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 ");

这是我的代码,我试图在数据库中的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 ");
    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++,有。包括头吗?乐意帮助,欢迎使用堆栈溢出。如果此答案解决了您的问题,请将其标记为已接受。