• Home
  • MySQL
  • PHP
  • Apache
  • About
  • Contact Us
 
 
 
  • MySQL 5.5 Reference Manual
  • MySQL 5.1 Reference Manual
  • MySQL 3.23/4.0/4.1 Manual
  • MySQL 4.0 Russian Manual


MySQL 3.23, 4.0, 4.1 Reference Manual :: 17 Connectors and APIs :: 17.6 MySQL C API :: 17.6.7 C API Prepared Statement Function Descriptions :: 17.6.7.20 mysql_stmt_prepare()
« 17.6.7.19 mysql_stmt_param_metadata()

17.6.7.21 mysql_stmt_reset() »
Section Navigation      [Toggle]
  • 17.6.7 C API Prepared Statement Function Descriptions
  • 17.6.7.1 mysql_stmt_affected_rows()
  • 17.6.7.2 mysql_stmt_attr_get()
  • 17.6.7.3 mysql_stmt_attr_set()
  • 17.6.7.4 mysql_stmt_bind_param()
  • 17.6.7.5 mysql_stmt_bind_result()
  • 17.6.7.6 mysql_stmt_close()
  • 17.6.7.7 mysql_stmt_data_seek()
  • 17.6.7.8 mysql_stmt_errno()
  • 17.6.7.9 mysql_stmt_error()
  • 17.6.7.10 mysql_stmt_execute()
  • 17.6.7.11 mysql_stmt_fetch()
  • 17.6.7.12 mysql_stmt_fetch_column()
  • 17.6.7.13 mysql_stmt_field_count()
  • 17.6.7.14 mysql_stmt_free_result()
  • 17.6.7.15 mysql_stmt_init()
  • 17.6.7.16 mysql_stmt_insert_id()
  • 17.6.7.17 mysql_stmt_num_rows()
  • 17.6.7.18 mysql_stmt_param_count()
  • 17.6.7.19 mysql_stmt_param_metadata()
  • 17.6.7.20 mysql_stmt_prepare()
  • 17.6.7.21 mysql_stmt_reset()
  • 17.6.7.22 mysql_stmt_result_metadata()
  • 17.6.7.23 mysql_stmt_row_seek()
  • 17.6.7.24 mysql_stmt_row_tell()
  • 17.6.7.25 mysql_stmt_send_long_data()
  • 17.6.7.26 mysql_stmt_sqlstate()
  • 17.6.7.27 mysql_stmt_store_result()

17.6.7.20. mysql_stmt_prepare()

int mysql_stmt_prepare(MYSQL_STMT *stmt, const char *stmt_str, unsigned long length)

Description

Given the statement handle returned by mysql_stmt_init(), prepares the SQL statement pointed to by the string stmt_str and returns a status value. The string length should be given by the length argument. The string must consist of a single SQL statement. You should not add a terminating semicolon (“;”) or \g to the statement.

The application can include one or more parameter markers in the SQL statement by embedding question mark (“?”) characters into the SQL string at the appropriate positions.

The markers are legal only in certain places in SQL statements. For example, they are allowed in the VALUES() list of an INSERT statement (to specify column values for a row), or in a comparison with a column in a WHERE clause to specify a comparison value. However, they are not allowed for 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 it would be impossible to determine the parameter type. In general, parameters are legal only in Data Manipulation Language (DML) statements, and not in Data Definition Language (DDL) statements.

The parameter markers must be bound to application variables using mysql_stmt_bind_param() before executing the statement.

This function was added in MySQL 4.1.2.

Return Values

Zero if the statement was prepared successfully. Nonzero if an error occurred.

Errors

  • CR_COMMANDS_OUT_OF_SYNC

    Commands were executed in an improper order.

  • CR_OUT_OF_MEMORY

    Out of memory.

  • CR_SERVER_GONE_ERROR

    The MySQL server has gone away.

  • CR_SERVER_LOST

    The connection to the server was lost during the query

  • CR_UNKNOWN_ERROR

    An unknown error occurred.

If the prepare operation was unsuccessful (that is, mysql_stmt_prepare() returns nonzero), the error message can be obtained by calling mysql_stmt_error().

Example

See the Example in Section 17.6.7.10, “mysql_stmt_execute()”.

Copyright © 1997, 2010, Oracle and/or its affiliates. All rights reserved. Legal Notices
Previous / Next / Up / Table of Contents

User Comments

Posted by Scott Bailey on September 29 2005 12:42am  

For those of you suffering from a "1047: Unknown command" error, ensure your client and server side MySQL versions are compatible.

Top / Previous / Next / Up / Table of Contents
Copyright © 2013, doc0.ru
All rights reserved