Home > php教程 > php手册 > 深入mysql_fetch_row()与mysql_fetch_array()的区别详解

深入mysql_fetch_row()与mysql_fetch_array()的区别详解

WBOY
Release: 2016-06-13 11:51:21
Original
731 people have browsed it

这两个函数,返回的都是一个数组,区别就是第一个函数返回的数组是只包含值,我们只能$row[0],
$row[1],这样以数组下标来读取数据,而mysql_fetch_array()返回的数组既包含第一种,也包含键值
对的形式,我们可以这样读取数据,(假如数据库的字段是 username,passwd):
$row['username'], $row['passwd']
而且,如果用($row as $kay => $value)来操作的话,还以直接取得数据库的字段名称。
更主要的是mysqli是php5提供的新函数库,(i)表示改进,其执行速度更快.
例如

复制代码 代码如下:


Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->//连接到本地mysql数据库,选择test为操作库
$mysqli = mysqli_connect("localhost", "root", "","test", 3306);
//用mysql_query函数从user表里读取数据
$result = mysqli_query($mysqli, "SELECT * FROM userinfo");
while($row = mysqli_fetch_array($result))//通过循环读取数据内容
{
?>


   
   
   

}
//关闭对数据库的连接
mysqli_free_result($result);
mysqli_close($mysqli);*/
?>

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template