mysql_stmt_prepare() prepares the SQL statement to which the stmt_str string points and returns a status value.
Syntax
int
mysql_stmt_prepare(MYSQL_STMT *stmt,
const char *stmt_str,
unsigned long length)
Return values
If the function is executed, zero is returned. If an error occurs, a non-zero value is returned.
Error messages
CR_COMMANDS_OUT_OF_SYNC: Commands are executed in an incorrect order.CR_OUT_OF_MEMORY: The memory is insufficient.CR_SERVER_GONE_ERROR: The connection to the OBServer was interrupted.CR_SERVER_LOST: The connection to the server was lost during the query.CR_UNKNOWN_ERROR: An unknown error occurred.
If mysql_stmt_prepare() returns a non-zero value, which indicates that the execution failed, you can call mysql_stmt_error() to get the error message.
Notes
mysql_stmt_prepare() specifies the statement handle to be returned by mysql_stmt_init(). You need to define the string length by specifying the length parameter. The string can contain only one SQL statement that does not have semicolons (;) or \g.
If you add question marks (?) at appropriate places in the SQL string, one or more parameter markers can be included in the SQL statement for applications.
It is valid to use markers in some places in an SQL statement. For example, you can use markers in the VALUES() list of an INSERT statement to specify column values of rows or when comparing with columns of a WHERE clause to specify the comparison values. However, you cannot use markers as identifiers such as table or column names or to specify both operands of a binary operator, such as the equal sign (=). The latter restriction is necessary because the parameter type cannot be determined. In general, parameters are valid only in data manipulation language (DML) statements and are invalid in data definition language (DDL) statements.
To execute a statement, you must use mysql_stmt_bind_param() to bind parameter markers to application variables.
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.