Home > database >  The use of mysql c API prepared statements
The use of mysql c API prepared statements

Time:11-14

Below is part of the code, I found that the result of the final output is null, not a string, help me to look at where the wrong


MYSQL_STMT * STMT=mysql_stmt_init (& amp; Mysql);//create a preprocessor statement handle
Char * query="select the account and password from c_table where account=(?) And password=(?) ";
Char * account and password;
If (mysql_stmt_prepare (STMT, query, strlen (query)))
{
Fprintf (stderr, "mysql_stmt_prepare: % s \ n", mysql_error (& amp; Mysql));//if prepared statements failure
}
MYSQL_BIND params [2], the bind [2].
Memset (params, 0, sizeof (params));//to empty
Memset (bind, 0, sizeof (bind));

Params [0]. Buffer_type=MYSQL_TYPE_LONGLONG;
Params [0]. Buffer=get_account;
Params [0]. Buffer_length=14;
Params [1]. Buffer_type=MYSQL_TYPE_LONGLONG;
Params [1]. The buffer=get_password;
Params [1]. Buffer_length=16;
Mysql_stmt_bind_param (STMT, params);
Result=mysql_stmt_result_metadata MYSQL_RES * (STMT);
Mysql_stmt_execute (STMT);
The bind [0]. Buffer_type=MYSQL_TYPE_LONGLONG;
The bind [0]. Buffer=& amp; The account;
The bind [1]. Buffer_type=MYSQL_TYPE_LONGLONG;
The bind [1]. The buffer=& amp; The password;
Mysql_stmt_bind_result (STMT, bind);//is bound to the buffer
Mysql_stmt_store_result (STMT);//return the result set
Mysql_stmt_fetch (STMT);
Printf (" % s ", the account);
  • Related