1
回答
调用mysql_stmt_bind_param函数出现段错误!
滴滴云服务器,限时包月0.9元,为开发者而生>>>   

部分程序如下

#define     GETUSER_CHAT "SELECT u_id, u_passwd FROM Users WHERE u_id = ? AND u_passwd = ?"



void    init_stmt(MYSQL_STMT *stmt, MYSQL *mysql, const char *str, int arg_count)
{
    int     param_count;
    stmt = mysql_stmt_init(mysql);                     /* init stmt for log */
    if (!stmt)
    {
        fprintf(stderr, "mysql_stmt_init(), Out of memery\n");
        exit(0);
    }

    if (mysql_stmt_prepare(stmt, str, strlen(str)))
        err_stmt_exit(stmt, "mysql_stmt_prepare(), failed");

    param_count = mysql_stmt_param_count(stmt);
    fprintf(stdout, "total parameters in stmt_log: %d\n", param_count);
    if (param_count != arg_count)
    {
        fprintf(stderr, "invalid parameter count return by MySQL(stmt_log)\n");
        exit(1);
    }
}



    /* login for selete u_id, u_password */
    MYSQL_STMT  *stmt_log;                      /* query Users table (id,pwd)*/
    MYSQL_BIND  bind_log[2];                    /* just bind id, passwd of User */
    int     uid;
    char    upasswd[30];

    /* create connection to mysql */
    connect_mysql(&mysql, "localhost", "user", "123456", "test", 0, NULL, 0);
    printf("connect to mysql success\n");

    /* set character set */
    if (mysql_set_character_set(&mysql, "utf8"))
        err_exit(&mysql, "mysql_set_character_set ");

    init_stmt(stmt_log, &mysql, GETUSER_CHAT, 2);
        printf("init_stmt stmt_log success\n");

    memset(bind_log, 0, sizeof(bind_log));

    bind_log[0].buffer_type = MYSQL_TYPE_LONG;
    bind_log[0].buffer = (char *)&uid;
    bind_log[0].is_null = 0;
    bind_log[0].length = 0;

    bind_log[1].buffer_type = MYSQL_TYPE_STRING;
    bind_log[1].buffer = (char *)upasswd;
    bind_log[1].buffer_length = 30;
    bind_log[1].is_null = 0;
    bind_log[1].length = (unsigned long *)&pass_len;
    if (mysql_stmt_bind_param(stmt_log, bind_log))
        err_stmt_exit(stmt_log, "mysql_stmt_bind_param() failed");



运行到这里就段错误了!
举报
锋了
发帖于3年前 1回/864阅
顶部