请教一个问题:用C操作MYSQL数据库时向数据库中插入一个字符串
char *a="123";
mysql_query=(connect,"UPDATE table1 SET ip=a);
但是结果不能正确插入。有什么其它的办法吗?

解决方案 »

  1.   

    这其实不是MYSQL的问题,是一个C中如何操作字符串的问题。 你需要让MYSQL执行的语句是 
    UPDATE table1 SET ip='123' 所以你需要想办法在C中生成这个字符串。
      

  2.   


    所以,要改成这样:char *a="123";
    mysql_query=(connect, sprintf("UPDATE table1 SET ip='%s';", a));改你的代码怎么发现那个代码到处是语法问题。
      

  3.   

    不行呀,会有警告:format not a string litral and no format arguments
    :passing argument 2 of 'mysql_query' makes pointer from integer without a cast因为临时做项目,现学的,所以是现学现用,还望前辈们多多包涵呀
      

  4.   

    mysql_query(connect, sprintf("UPDATE table1 SET ip='%s';", a));
      

  5.   

    mysql_query(connect,"UPDATE table1 SET ip='123'");
    试试看行不行先。
      

  6.   

    经过一番努力,结贴了
    char * a;
    char sql[20];
    sprintf(sql,"UPDATE table1 SET ip='%s'",a);
    mysql_query(connect,sql);注:'%s'后没有分号