mysql_fetch_row() 和mysql_fetch_array之间有什么区别?该如何处理

WBOY
Release: 2016-06-13 10:18:49
Original
879 people have browsed it

mysql_fetch_row() 和mysql_fetch_array之间有什么区别?
mysql_fetch_row() 和mysql_fetch_array之间有什么区别?

------解决方案--------------------
这两个函数,返回的都是一个数组,区别就是第一个函数返回的数组是只包含值,我们只能$row[0],$row[1],这样以数组下标来读取数据,而MySQL_fetch_array()返回的数组既包含第一种,也包含键值对的形式,我们可以这样读取数据,(假如数据库的字段是 username,passwd):

$row['username'], $row['passwd']
------解决方案--------------------
mysql_fetch_row是从结果集取出1行数组,作为枚举 

mysql_fetch_array是从结果集取出一行数组作为关联数组,或数字数组,两者兼得


eg:
$sql="select abc,def from a";
$res=mysql_query($sql);

那么:
$row=mysql_fetch_row($res);
$row结果是两个:$row[0]和$row[1]
那么:
$row=mysql_fetch_array($res);
$row结果是4个:$row[0]、$row[1]、$row["abc"]和$row["def"]

Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!