PHP function MySQL

Source: Internet
Author: User

First, Mysql_fetch_row

This function takes one row from the result set as the enumeration data, and takes a row of data from the result set associated with the specified result identity and returns as an array. The columns of each result are stored in a cell of an array, with an offset starting at 0.

Note that this is offset from 0, which means that you cannot use the field name to take the value, only the index. For example:

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

echo $row [' CID ']. >>> '. $row [1]. '


The $row[' CID ' here is not a value, $row [1] can be taken.


Take a row from the result set as an associative array, which means that the function cannot be indexed as Mysql_fetch_row, only with the name of the field. For example:

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

echo $row [' CID ']. >>> '. $row [1]. '


Here $row[1] This is not a value, $row [' CID '] can be taken.

Third, Mysql_fetch_array

Take a row from the result set as an associative array, or an array of numbers, or both, to store the data as an associative index, in addition to storing the data in a digital index, with the field name as the key name.

That means he gets the same result as an array, and can use key or index to get the value. For example:

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

echo $row [' CID ']. >>> '. $row [1]. '


Here $row[' CID ', $row [1] can get the corresponding value.

The Mysql_fetch_row and MYSQL_FETCH_ASSOC functions add up to the mysql_fetch_array.

Four, Mysql_fetch_object

As the name suggests, take a row from the result set as an object, and make the field name a property. So that's the only way to get the value:

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

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


Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.