Three common methods for php to access and query mysql data

WBOY
Release: 2016-08-08 09:33:48
Original
1371 people have browsed it

There are three common methods for PHP to access and query MySQL data:

1. $row = MySQL_fetch_row($result);

Returns a regular array $row, $row[0] is the first element, $row[1] is the second element, and so on...
mysql_num_fields($result) returns the number of elements in the result.

2. $row = mysql_fetch_array($result);

Returns an array $row. For example:
The table structure is as follows:

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

The first time you run $row = mysql_fetch_array($result), the result is as follows:

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

The first time you run $row = mysql_fetch_array($result), the result is as follows:

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


3. $row = mysql_fetch_object($result);

Returns an object description row. As in the above example
The first time you run $row = mysql_fetch_object($result), the results are as follows:

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

The second time you run $row = mysql_fetch_object($result), the results are as follows:
$row->username = "berber"
$row->password = "efg"

The above introduces the three commonly used methods of accessing and querying MySQL data in PHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

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!