本人是初学者,提的问题也比较简单。
我看文档上写的mysql_real_query()可以处理带"\0"的字符串,可以我写了一条带"\0"字符的查询语句,结果却报错,去掉"\0"就没问题。(在sql里加"\0"字符,只是为了测试)
#include <mysql.h>
#include <stdio.h>
int main()
{
        MYSQL mysql;
        MYSQL_RES *res;
        MYSQL_ROW row;
        char query[]="select * \0 from t_staff";
        int t,r;
        mysql_init(&mysql);
        if (!mysql_real_connect(&mysql,"localhost", "root", "111", "mydb",0,NULL,0))
        {
                printf( "Error connecting to database: %s\n",mysql_error(&mysql));
        }
        else
                printf("Connected...\n");        t = mysql_real_query(&mysql,query,sizeof(query);
        if (t)
        {
                printf("Error making query: %s\n",
                mysql_error(&mysql));
        }
        else
                printf("[%s] made...\n", query);
        res = mysql_store_result(&mysql);报错信息Error making query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1请高手们解答一下。

解决方案 »

  1.   

    select *, \0 from t_staff
      

  2.   

    还是报错。
    Error making query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server ve
    rsion for the right syntax to use near '' at line 1
         15 [main] mysql 2140 _cygtls::handle_exceptions: Error while dumping state (probably corrupted stack)
    Segmentation fault (core dumped)
      

  3.   

    不是吧,我在SQLYOG+MYSQL5.0中测试,没有问题
      

  4.   

    mysql_query() cannot be used for statements that contain binary data; you must use mysql_real_query() instead. (Binary data may contain the “\0” character, which mysql_query() interprets as the end of the statement string.) In addition, mysql_real_query() is faster than mysql_query() because it does not call strlen() on the statement string. 
      

  5.   

    你先直接在你的数据库下执行你的sql语句看有错不,
    select * \0 from t_staff;
      

  6.   

    sizeof(query); 
    多少呢?我用c语言的例子试试。