从结果集中取得一行作为关联数组:
<?php // 假定数据库用户名:root,密码:123456,数据库:RUNOOB $con=mysqli_connect("localhost","root","123456","RUNOOB"); 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_assoc($result); printf ("%s : %s)",$row["name"],$row["url"]); // 释放结果集 mysqli_free_result($result); mysqli_close($con); ?>
mysqli_fetch_assoc() 函数从结果集中取得一行作为关联数组。
注释:该函数返回的字段名是区分大小写的。
从结果集中取得行
<?php // 假定数据库用户名:root,密码:123456,数据库:RUNOOB $con=mysqli_connect("localhost","root","123456","RUNOOB"); if (mysqli_connect_errno($con)) { echo "连接 MySQL 失败: " . mysqli_connect_error(); } $sql="SELECT name,url FROM websites ORDER BY alexa"; if ($result=mysqli_query($con,$sql)) { // 一条条获取 while ($row=mysqli_fetch_row($result)) { printf ("%s : %s",$row[0],$row[1]); echo "<br>"; } // 释放结果集合 mysqli_free_result($result); } mysqli_close($con); ?>
mysqli_fetch_row() 函数从结果集中取得一行,并作为枚举数组返回。
php中mysqli_fetch_assoc()和mysqli_fetch_row()的区别
原文:https://www.cnblogs.com/Yaucheun/p/10447808.html