目录
- 6.1 C API 预处理语句接口概述
- 6.2 C API 准备语句数据结构
- 6.3 C API 预处理语句函数参考
- 6.4 C API 预处理语句函数说明
- 6.4.1 mysql_stmt_affected_rows()
- 6.4.2 mysql_stmt_attr_get()
- 6.4.3 mysql_stmt_attr_set()
- 6.4.4 mysql_stmt_bind_param()
- 6.4.5 mysql_stmt_bind_result()
- 6.4.6 mysql_stmt_close()
- 6.4.7 mysql_stmt_data_seek()
- 6.4.8 mysql_stmt_errno()
- 6.4.9 mysql_stmt_error()
- 6.4.10 mysql_stmt_execute() 函数
- 6.4.11 mysql_stmt_fetch()
- 6.4.12 mysql_stmt_fetch_column()
- 6.4.13 mysql_stmt_field_count()
- 6.4.14 mysql_stmt_free_result()
- 6.4.15 mysql_stmt_init()
- 6.4.16 mysql_stmt_insert_id()
- 6.4.17 mysql_stmt_next_result()
- 6.4.18 mysql_stmt_num_rows()
- 6.4.19 mysql_stmt_param_count()
- 6.4.20 mysql_stmt_param_metadata()
- 6.4.21 mysql_stmt_prepare()
- 6.4.22 mysql_stmt_reset()
- 6.4.23 mysql_stmt_result_metadata()
- 6.4.24 mysql_stmt_row_seek()
- 6.4.25 mysql_stmt_row_tell()
- 6.4.26 mysql_stmt_send_long_data()
- 6.4.27 mysql_stmt_sqlstate()
- 6.4.28 mysql_stmt_store_result()
The MySQL client/server protocol provides for the use of prepared
statements. This capability uses the MYSQL_STMT
statement handler data structure returned by the
mysql_stmt_init()
initialization
function. Prepared execution is an efficient way to execute a
statement more than once. The statement is first parsed to prepare
it for execution. Then it is executed one or more times at a later
time, using the statement handler returned by the initialization
function.
对于多次执行的语句,准备执行比直接执行更快,主要是因为查询只被解析一次。在直接执行的情况下,每次执行都会解析查询。准备执行还可以减少网络流量,因为对于准备语句的每次执行,只需要发送参数数据。
在某些情况下,准备好的语句可能不会提供性能提升。为获得最佳结果,请使用准备好的和非准备的语句测试您的应用程序,并选择产生最佳性能的那个。
准备好的语句的另一个优点是它使用二进制协议,使客户端和服务器之间的数据传输更加高效。
For a list of SQL statements that can be used as prepared statements, see Prepared Statements.
Metadata changes to tables or views referred to by prepared statements are detected and cause automatic repreparation of the statement when it is next executed. For more information, see Caching of Prepared Statements and Stored Programs.