I am trying to execute a C program using the mysql C API, connecting to mysql asking for an update, and I am not getting any compilation or error links, but the rows are not updating in the db table.
When I run this code, I get empty values ββupdated in emp. status field
#define STRING_SIZE 256 char* eStatus,myeStatus; int myempid,empid; int i; for(i = 0; i < 5 ; i++){ const char* sqlQuery = "update employee_info set estatus = ? where empID = ?"; if (mysql_stmt_prepare(stmt, sqlQuery, strlen(sqlQuery))) { fprintf(stderr, " mysql_stmt_prepare(), update failed\n"); fprintf(stderr, " %s\n", mysql_stmt_error(stmt)); return -1; } memset(param, 0, sizeof(param)); /* zero the structures */ if (info.state == 2) eStatus = "present"; else eStatus = "absent"; empid = i; // Init param structure // Select param[0].buffer_type = MYSQL_TYPE_STRING; param[0].buffer = (void *) &eStatus; param[0].buffer_length = STRING_SIZE; param[0].is_null = 0; param[0].length = &str_length; param[1].buffer_type = MYSQL_TYPE_SHORT; param[1].buffer = (void *) &myempID; param[1].buffer_length = STRING_SIZE; param[1].is_null = 0; param[1].length = 0; myeStatus = eStatus; myempid = empid; if (mysql_stmt_bind_param(stmt, param) != 0) { fprintf(stderr, " mysql_stmt_bind_param() failed\n"); fprintf(stderr, " %s\n", mysql_stmt_error(stmt)); return -1; } /* Execute the statement */ if (mysql_stmt_execute(stmt)) { fprintf(stderr, " mysql_stmt_execute(), failed\n"); fprintf(stderr, " %s\n", mysql_stmt_error(stmt)); return -1; } } // end of for loop
Table schema in mysql
empid INT (11)
estatus varchar (10)
I can not understand why the status is not updated in the mysql table. Is this a data type mismatch, or are the values ββnot properly bound to sqlquery?
Any clue? Thanks.
source share