Note that there are some explanatory texts on larger screens.

plurals
  1. POmysql prepared statement : Update query
    primarykey
    data
    text
    <p>I am trying to execute a C program, using mysql C API, connecting to mysql with an update query and I am not getting any compilation or linking errors , but rows are not getting updated in the db table.</p> <p>When I run this code I am getting empty values updated in emp. status field</p> <pre><code>#define STRING_SIZE 256 char* eStatus,myeStatus; int myempid,empid; int i; for(i = 0; i &lt; 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 *) &amp;eStatus; param[0].buffer_length = STRING_SIZE; param[0].is_null = 0; param[0].length = &amp;str_length; param[1].buffer_type = MYSQL_TYPE_SHORT; param[1].buffer = (void *) &amp;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 </code></pre> <p>Table schema in mysql</p> <p>empid INT(11)</p> <p>estatus varchar(10)</p> <p>I am not able to figure out why status is not getting updated in mysql table. Is it a mismatch of datatypes, or values are not binded properly to sqlquery?<br> Any clue? Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload