Need x86 prepared statement example
I need to find a simple example of an x86 (32-bit) program using the 6.1 connector with a string parameter and a string result. In PHP, the following works (error checks omitted for clarity):
$stmt = mysqli_stmt_init(<database object>);
mysqli_stmt_prepare($stmt, "select textfield from database where key=?");
mysqli_stmt_bind_param($stmt, "s", $stringval);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $textvar);
mysqli_stmt_fetch($stmt);
After three days of trying and looking online, I can't duplicate this functionality using the C-API. I think my problem relates to correctly initializing the MYSQL_BIND structures, but none of the several samples I've found online seems to work for me. E.g.:
char keyval[] = "sample";
int strl_len = 256;
char strval[256];
MYSQL* h = mysql_init(NULL);
MYSQL_STMT* stmt = mysql_stmt_init(h);
char* query = "select textfield from database where key=?";
mysql_stmt_prepare($stmt, query, strlen(query));
MYSQL_BIND pbind, qbind;
memset(&pbind, 0, sizeof(pbind));
pbind.buffer = keyval;
pbind.buffer_length = strlen(keyval) + 1;
pbind.buffer_type = MYSQL_TYPE_STRING;
pbind.error = etc.;
pbind.length = &str_len;
mysql_stmt_bind_param(stmt, &pdind);
mysql_stmt_execute(stmt);
// mysql.general_log shows execution of select textfield from database
// where keyval=NULL
memset(&qbind, 0, sizeof(qbind);
qbind.buffer = strval;
qbind.buffer_length = 256;
qbind.buffer_type = MYSQL_TYPE_STRING;
qbind.length = &str_len;
mysql_stmt_bind_result($stmt, &qbind);
mysql_stmt_store_result($stmt);
mysql_stmt_fetch(stmt);
All API calls before fetch succeed. Fetch returns 257, which means "no more rows", even for the first row of the result set.