jwnlive
V2EX  ›  问与答

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

  •  
  •   jwnlive · Nov 3, 2014 · 3604 views
    This topic created in 4220 days ago, the information mentioned may be changed or developed.
    #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,请帮忙构造一个语句,多谢
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3094 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 13:44 · PVG 21:44 · LAX 06:44 · JFK 09:44
    ♥ Do have faith in what you're doing.