array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'mysqli-stmt.store-result.php', 1 => 'mysqli_stmt::store_result', ), 'up' => array ( 0 => 'class.mysqli-stmt.php', 1 => 'mysqli_stmt', ), 'prev' => array ( 0 => 'mysqli-stmt.sqlstate.php', 1 => 'mysqli_stmt::$sqlstate', ), 'next' => array ( 0 => 'class.mysqli-result.php', 1 => 'mysqli_result', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/mysqli/mysqli_stmt/store-result.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5, PHP 7, PHP 8)
mysqli_stmt::store_result -- mysqli_stmt_store_result — Stores a result set in an internal buffer
面向对象风格
过程化风格
This function should be called for queries that successfully
produce a result set (e.g. SELECT, SHOW, DESCRIBE, EXPLAIN
)
only if the complete result set needs to be buffered in PHP. Each subsequent
mysqli_stmt_fetch() call will return buffered data.
注意:
It is unnecessary to call mysqli_stmt_store_result() for other queries, but if you do, it will not harm or cause any notable performance loss in all cases. You can detect whether the query produced a result set by checking if mysqli_stmt_result_metadata() returns
false
.
If mysqli error reporting is enabled (MYSQLI_REPORT_ERROR
) and the requested operation fails,
a warning is generated. If, in addition, the mode is set to MYSQLI_REPORT_STRICT
,
a mysqli_sql_exception is thrown instead.
示例 #1 面向对象风格
<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
$query = "SELECT Name, CountryCode FROM City ORDER BY Name LIMIT 20";
$stmt = $mysqli->prepare($query);
$stmt->execute();
/* store the result in an internal buffer */
$stmt->store_result();
printf("Number of rows: %d.\n", $stmt->num_rows);
示例 #2 过程化风格
<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
$query = "SELECT Name, CountryCode FROM City ORDER BY Name LIMIT 20";
$stmt = mysqli_prepare($link, $query);
mysqli_stmt_execute($stmt);
/* store the result in an internal buffer */
mysqli_stmt_store_result($stmt);
printf("Number of rows: %d.\n", mysqli_stmt_num_rows($stmt));
以上示例会输出:
Number of rows: 20.