Home > Backend Development > PHP Tutorial > php访问查询mysql数据的三种方法

php访问查询mysql数据的三种方法

WBOY
Release: 2016-06-01 14:30:48
Original
1061 people have browsed it
1. $row = MySQL_fetch_row($result);
返回一个规则的数组$row,$row[0]是第一个元素,$row[1]是第二个元素,依次类推...
mysql_num_fields($result) 返回结果的元素个数。

2. $row = mysql_fetch_array($result);

返回一个数组$row. 举例如下:
表结构如下:

username | passWord
-------------------------------------
bourbon | abc
berber | efg

第一次运行运行 $row = mysql_fetch_array($result) 则结果如下:

$row[0] = $row["username"] = "bourbon"
$row[1] = $row["password"] = "abc"

第一次运行运行 $row = mysql_fetch_array($result) 则结果如下:

$row[0] = $row["username"] = "berber"
$row[1] = $row["password"] = "efg"


3. $row = mysql_fetch_object($result);

返回一个对象描述行. 如上例
第一次运行运行$row = mysql_fetch_object($result) 则结果如下:

$row->username = "bourbon"
$row->password = "abc"

第二次运行运行$row = mysql_fetch_object($result) 则结果如下:
$row->username = "berber"
$row->password = "efg" 

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