Differences between PHP functions mysql_fetch_row, assoc, array, and object_PHP tutorial

WBOY
Release: 2016-07-13 10:07:35
Original
1052 people have browsed it

The difference between PHP functions mysql_fetch_row, assoc, array and object

1. mysql_fetch_row

This function takes a row from the result set as enumeration data, obtains a row of data from the result set associated with the specified result identifier, and returns it as an array. Each result column is stored in a cell of the array, starting at offset 0.

Note that the offset here starts from 0, which means that the field name cannot be used to obtain the value, only the index can be used to obtain the value. For example:

while($row = mysql_fetch_row($res)){

echo $row['cid'].'>>>'.$row[1].'
';

 }

The value of $row['cid'] here cannot be obtained, but $row[1] can.

2. mysql_fetch_assoc

Get a row from the result set as an associative array, which means that this function cannot use the index to get the value like mysql_fetch_row, but can only use the field name to get the value. For example:

while($row = mysql_fetch_assoc($res)){

echo $row['cid'].'>>>'.$row[1].'
';

 }

Here $row[1] cannot get the value, but $row['cid'] can.

3. mysql_fetch_array

Get a row from the result set as an associative array, or a numeric array, or both. In addition to storing the data in the array as a numeric index, you can also store the data as an associative index, using the field name as the key. name.

That is to say, the result he gets is like an array, and the value can be obtained by key or index. For example:

while($row = mysql_fetch_array($res)){

echo $row['cid'].'>>>'.$row[1].'
';

 }

Here $row['cid'] and $row[1] can get corresponding values.

The functions of mysql_fetch_row and mysql_fetch_assoc add up to mysql_fetch_array.

4. mysql_fetch_object

As the name suggests, get a row from the result set as an object and use the field name as an attribute. So the only way to get the value is:

while($row = mysql_fetch_object($res)){

echo $row->cid.'>>>'.$row->title."
";

 }

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/955270.htmlTechArticleDifferences between PHP functions mysql_fetch_row, assoc, array, and object 1. mysql_fetch_row This function takes a row from the result set as an enumeration Cite data from results associated with the specified result identifier...
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!