mysqli_stmt::store_result
mysqli_stmt::store_result
mysqli_stmt_store_result
(PHP 5, PHP 7)
mysqli_stmt :: store_result - mysqli_stmt_store_result - 从预准备语句传输结果集
描述
面向对象的风格
bool mysqli_stmt::store_result ( void )
程序风格
bool mysqli_stmt_store_result ( mysqli_stmt $stmt )
当且仅当您想缓冲客户端的完整结果集时,您必须为每个成功生成结果集(SELECT,SHOW,DESCRIBE,EXPLAIN
)的查询调用mysqli_stmt_store_result()
,以便随后的mysqli_stmt_fetch()调用返回缓冲数据。
注意
:不需要为其他查询调用mysqli_stmt_store_result()
,但如果这样做,它不会在所有情况下造成任何显着的性能损失。您可以通过检查mysqli_stmt_result_metadata()是否返回NULL来检测查询是否生成结果集。
参数
`stmt`
仅过程风格:由mysqli_stmt_init()返回的语句标识符。
返回值
返回TRUE
成功或返回FALSE
失败。
例子
Example #1 Object oriented style
<?php
/* Open a connection */
$mysqli = new mysqli("localhost", "my_user", "my_password", "world"
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error()
exit(
}
$query = "SELECT Name, CountryCode FROM City ORDER BY Name LIMIT 20";
if ($stmt = $mysqli->prepare($query)) {
/* execute query */
$stmt->execute(
/* store result */
$stmt->store_result(
printf("Number of rows: %d.\n", $stmt->num_rows
/* free result */
$stmt->free_result(
/* close statement */
$stmt->close(
}
/* close connection */
$mysqli->close(
?>
Example #2 Procedural style
<?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(
}
$query = "SELECT Name, CountryCode FROM City ORDER BY Name LIMIT 20";
if ($stmt = mysqli_prepare($link, $query)) {
/* execute query */
mysqli_stmt_execute($stmt
/* store result */
mysqli_stmt_store_result($stmt
printf("Number of rows: %d.\n", mysqli_stmt_num_rows($stmt)
/* free result */
mysqli_stmt_free_result($stmt
/* close statement */
mysqli_stmt_close($stmt
}
/* close connection */
mysqli_close($link
?>
上面的例子会输出:
Number of rows: 20.