PDF (Ltr)- 2.4 mb
PDF (A4)- 2.4 mb
版权1997 - 2022 PHP文档组。10bet官方网站
作用是
获取一个结果行作为一个关联数组中
警告
这个扩展在PHP里弃用,这是在PHP 7.0.0删除。相反,MySQLi或PDO_MySQL应该使用扩展。另请参阅MySQL:选择一个API指南。选择这个函数包括:
mysqli_fetch_assoc |
PDOStatement::获取(PDO:: FETCH_ASSOC) |
描述
数组作用是(资源结果);
返回一个关联数组中对应于所获取的行和内部数据指针移动。作用是
相当于调用mysql_fetch_array
与MYSQL_ASSOC可选的第二个参数。它只是返回一个关联数组中。
参数
-
结果
-
结果资源正在评估。这个结果来自一个调用
mysql_query
。
返回值
返回一个字符串关联数组对应于所获取的行,或假
如果没有其他行。
如果两个或多个列的结果有相同的字段名,最后一列将优先。访问相同的名称的其他列(s),你需要访问结果数字索引的使用mysql_fetch_row
或添加别名。看到的例子mysql_fetch_array
描述关于别名。
例子
6.21示例扩展作用是
例子
< ?php $康涅狄格州= mysql_connect (“localhost”、“mysql_user”、“mysql_password”);如果(! $康涅狄格州){回声“无法连接到DB:”。mysql_error ();退出;}如果(! mysql_select_db (“mydbname”)){回声“无法选择mydbname:”。mysql_error ();退出;}$ sql = "选择id作为用户标识、fullname userstatus从sometable userstatus = 1”;美元$结果= mysql_query (sql); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } // While a row of data exists, put that row in $row as an associative array // Note: If you're expecting just one row, no need to use a loop // Note: If you put extract($row); inside the following loop, you'll // then create $userid, $fullname, and $userstatus while ($row = mysql_fetch_assoc($result)) { echo $row["userid"]; echo $row["fullname"]; echo $row["userstatus"]; } mysql_free_result($result); ?>
笔记
性能
要注意的是,使用一个重要的事情作用是
是不显著低于使用mysql_fetch_row
,它提供了一个重要的附加价值。
请注意
这个函数返回的字段名区分大小写的。
请注意
这个函数将空字段设置为PHP零
价值。
另请参阅
mysql_fetch_row |
mysql_fetch_array |
mysql_data_seek |
mysql_query |
mysql_error |