lfzyx
V2EX  ›  C

MySQL Connector/C 插入数据

  •  
  •   lfzyx · Jun 11, 2015 · 1191 views
    This topic created in 4014 days ago, the information mentioned may be changed or developed.
    c语言连接mysql数据库用int mysql_query(MYSQL *mysql, const char *stmt_str)函数插入数据.

    mysql_query(conn, "INSERT INTO `list` (`ipaddress`) VALUES ('192.168.1.1')")

    我想把'192.168.1.1'用变量替代,但是替换成变量名后插入数据库的就是变量名本身,不是变量值。

    如何让mysql_query()可以获取变量值?
    1 replies    2015-06-11 17:20:20 +08:00
    nybux
        1
    nybux  
       Jun 11, 2015   ❤️ 1
    mysql_query不行,你要用mysql_stmt_init/mysql_stmt_bind_param这样
    你看看这个文章吧
    http://blog.csdn.net/leibniz_zsu/article/details/1627449
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5609 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 01:33 · PVG 09:33 · LAX 18:33 · JFK 21:33
    ♥ Do have faith in what you're doing.