You can call the mysql_stmt_execute() function to execute a prepared query associated with a statement handler.
Syntax
int
mysql_stmt_execute(MYSQL_STMT *stmt)
Return values
0 is returned for an execution success, and a non-zero value is returned for errors.
Errors
CR_COMMANDS_OUT_OF_SYNC: Commands were executed in an improper order.CR_OUT_OF_MEMORY: The memory is insufficient.CR_SERVER_GONE_ERROR: The connection to the OBServer was disconnected.CR_SERVER_LOST: The connection to the server was lost during the query.CR_UNKNOWN_ERROR: An unknown error occurred.
Notes
The currently bound parameter marker values are sent to the server during this call, and the server replaces the markers with the newly provided data.
Statement processing after mysql_stmt_execute() depends on the type of statement:
For an
UPDATE,DELETE, orINSERTstatement, the number of modified, deleted, or inserted rows can be obtained by callingmysql_stmt_affected_rows().For a statement such as
SELECTthat generates a result set, you must callmysql_stmt_fetch()to fetch the data before calling any other functions that result in query processing.Do not call
mysql_store_result()ormysql_use_result()after callingmysql_stmt_execute(). These functions are not used for processing results from prepared statements.For statements that generate a result set, you can request
mysql_stmt_execute()to open a cursor for the statement by callingmysql_stmt_attr_set()before executing the statement. If you execute a statement multiple times,mysql_stmt_execute()closes any open cursor before opening a new one.If it is detected that the metadata of a table or view referred to by a prepared statement is changed, the statement is automatically re-prepared the next time when the statement is executed.