mysqli_stmt::fetch
mysqli_stmt::fetch
mysqli_stmt_fetch
(PHP 5, PHP 7)
mysqli_stmt :: fetch - mysqli_stmt_fetch - 从准备好的语句中获取结果到绑定变量中
描述
面向对象的风格
bool mysqli_stmt::fetch ( void )
程序风格
bool mysqli_stmt_fetch ( mysqli_stmt $stmt )
从准备好的语句中获取结果到由mysqli_stmt_bind_result()绑定的变量中。
注意
:请注意
,在调用mysqli_stmt_fetch()
之前,所有列都必须由应用程序绑定。
注意
:数据在不调用mysqli_stmt_store_result()的情况下可以无缓冲传输,这会降低性能(但会降低内存成本)。
参数
`stmt`
仅过程风格:由mysqli_stmt_init()返回的语句标识符。
返回值
值 | 描述 |
---|---|
真正 | 成功。数据已被提取 |
假 | 发生了错误 |
空值 | 没有更多的行/数据存在或发生数据截断 |
例子
Example #1 Object oriented style
<?php
$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 ID DESC LIMIT 150,5";
if ($stmt = $mysqli->prepare($query)) {
/* execute statement */
$stmt->execute(
/* bind result variables */
$stmt->bind_result($name, $code
/* fetch values */
while ($stmt->fetch()) {
printf ("%s (%s)\n", $name, $code
}
/* close statement */
$stmt->close(
}
/* close connection */
$mysqli->close(
?>
Example #2 Procedural style
<?php
$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 ID DESC LIMIT 150,5";
if ($stmt = mysqli_prepare($link, $query)) {
/* execute statement */
mysqli_stmt_execute($stmt
/* bind result variables */
mysqli_stmt_bind_result($stmt, $name, $code
/* fetch values */
while (mysqli_stmt_fetch($stmt)) {
printf ("%s (%s)\n", $name, $code
}
/* close statement */
mysqli_stmt_close($stmt
}
/* close connection */
mysqli_close($link
?>
上面的例子会输出: