首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

mysqli_stmt::fetch

(PHP 5, PHP 7)

mysqli_stmt :: fetch - mysqli_stmt_fetch - 从准备好的语句中获取结果到绑定变量中

描述

面向对象的风格

代码语言:javascript
复制
bool mysqli_stmt::fetch ( void )

程序风格

代码语言:javascript
复制
bool mysqli_stmt_fetch ( mysqli_stmt $stmt )

从准备好的语句中获取结果到由mysqli_stmt_bind_result()绑定的变量中。

注意:请注意,在调用mysqli_stmt_fetch()之前,所有列都必须由应用程序绑定。

注意:数据在不调用mysqli_stmt_store_result()的情况下可以无缓冲传输,这会降低性能(但会降低内存成本)。

参数

代码语言:txt
复制
`stmt`   

仅过程风格:由mysqli_stmt_init()返回的语句标识符。

返回值

描述

真正

成功。数据已被提取

发生了错误

空值

没有更多的行/数据存在或发生数据截断

例子

Example #1 Object oriented style

代码语言:javascript
复制
<?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

代码语言:javascript
复制
<?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);
?>

上面的例子会输出:

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com