Latest web development tutorials

PHP mysqli_fetch_assoc () function

PHP MySQLi Reference Manual PHP MySQLi Reference Manual

Returns a row from the result as an associative array:

<?php 
// 假定数据库用户名:root,密码:123456,数据库:w3big 
$con=mysqli_connect("localhost","root","123456","w3big"); 
if (mysqli_connect_errno($con)) 
{ 
    echo "连接 MySQL 失败: " . mysqli_connect_error(); 
} 

$sql="SELECT name,url FROM websites ORDER BY alexa";
$result=mysqli_query($con,$sql);

// 关联数组
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
printf ("%s : %s)",$row["name"],$row["url"]);

// 释放结果集
mysqli_free_result($result);

mysqli_close($con);
?>

Definition and Usage

mysqli_fetch_assoc () function Returns a row as an associative array from the results.

Note: Field names returned by this function are case-sensitive.


grammar

mysqli_fetch_assoc( result ) ;

参数 描述
result 必需。规定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的结果集标识符。

technical details

return value: Back on behalf of row read associative array. If there are no more rows in the result set returns NULL.
PHP version: 5+


PHP MySQLi Reference Manual PHP MySQLi Reference Manual