V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
jwnlive
V2EX  ›  问与答

C 语言数组插入 mysql 数据库 求助

  •  
  •   jwnlive · 2014-11-03 10:37:16 +08:00 · 2823 次点击
    这是一个创建于 3462 天前的主题,其中的信息可能已经有所发展或是发生改变。
    #include <stdio.h>
    #include <stdlib.h>
    #include <mysql/mysql.h>

    int main(int argc, char *argv[])
    {
    MYSQL *my_con = malloc( sizeof(MYSQL) );
    MYSQL_RES *my_res;
    MYSQL_FIELD *my_field;
    MYSQL_ROW my_row;
    int rows, i;
    int res;

    int a[2] = {51,2};
    printf("%3d ",a[0]);

    mysql_init(my_con);
    my_con = mysql_real_connect(my_con, "localhost", "root", "jwn.com",
    "jwn", 0, NULL, CLIENT_FOUND_ROWS);
    if( NULL == my_con )
    error_quit("Connection fail", my_con);
    printf("Connection success\n");


    res = mysql_query(my_con,
    "insert into class1(name, age, birthday) value('abc', 52, NOW());");

    mysql_free_result(my_res);
    mysql_close(my_con);
    free(my_con);

    return 0;
    }
    ==============
    想要实现 int a[2] = {51,2}; 中的元素 插入 res = mysql_query(my_con,
    "insert into class1(name, age, birthday) value('abc', 52, NOW());"); 代替 52 插入51,请帮忙构造一个语句,多谢
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5604 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 03:11 · PVG 11:11 · LAX 20:11 · JFK 23:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.