定义和用法
mysqli_stmt_execute - 执行准备好的查询
版本支持PHP4PHP5PHP7不支持支持支持
语法mysqli_stmt_execute ( mysqli_stmt $stmt )
执行以前使用 mysqli_prepare() 函数准备的查询。 执行后,任何存在的参数标记将自动替换为适当的数据。 如果该语句是UPDATE,DELETE或INSERT,则可以使用 mysqli_stmt_affected_rows() 函数确定受影响的行总数。 同样,如果查询产生结果集,则使用 mysqli_stmt_fetch() 函数。注意: 使用mysqli_stmt_execute()时,必须在执行任何其他查询之前使用mysqli_stmt_fetch()函数来获取数据。
参数参数必需的描述stmt是由 mysqli_stmt_init() 返回的 statement 标识。
返回值
成功时返回 TRUE, 或者在失败时返回 FALSE。
示例<?php
/* Open a connection */
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
mysqli_query($link, "CREATE TABLE myCountry LIKE Country");
mysqli_query($link, "INSERT INTO myCountry SELECT * FROM Country");
$query = "SELECT Name, Code FROM myCountry ORDER BY Name";
if ($stmt = mysqli_prepare($link, $query)) {
/* drop table */
mysqli_query($link, "DROP TABLE myCountry");
/* execute query */
mysqli_stmt_execute($stmt);
printf("Error: %s.\n", mysqli_stmt_execute($stmt));
/* close statement */
mysqli_stmt_close($stmt);
}
/* close connection */
mysqli_close($link);
相关函数