mysqli_result::fetch_row
mysqli_result::fetch_row
mysqli_fetch_row
(PHP 5, PHP 7)
mysqli_result :: fetch_row -- mysqli_fetch_row — 将结果行作为枚举数组
描述
面向对象的风格
mixed mysqli_result::fetch_row ( void )
程序风格
mixed mysqli_fetch_row ( mysqli_result $result )
从结果集中提取一行数据,并将其作为枚举数组返回,其中每列存储在从0(零)开始的数组偏移量中。随后对此函数的每次调用将返回结果集中的下一行,或者NULL
如果没有更多行。
参数
`result`
仅过程风格:由mysqli_query(),mysqli_store_result()或mysqli_use_result()返回的结果集标识符。
返回值
mysqli_fetch_row()
返回对应于获取行的字符串数组,或者NULL
结果集中没有更多行。
注意
:该函数将NULL
字段设置为PHPNULL
值。
例子
Example#1面向对象的风格
<?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 50,5";
if ($result = $mysqli->query($query)) {
/* fetch object array */
while ($row = $result->fetch_row()) {
printf ("%s (%s)\n", $row[0], $row[1]
}
/* free result set */
$result->close(
}
/* close connection */
$mysqli->close(
?>
示例#2程序风格
<?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 50,5";
if ($result = mysqli_query($link, $query)) {
/* fetch associative array */
while ($row = mysqli_fetch_row($result)) {
printf ("%s (%s)\n", $row[0], $row[1]
}
/* free result set */
mysqli_free_result($result
}
/* close connection */
mysqli_close($link
?>
上面的例子会输出:
Pueblo (USA)
Arvada (USA)
Cape Coral (USA)
Green Bay (USA)
Santa Clara (USA)