Differences between php functions mysql_fetch_row, assoc, array, and object _ PHP Tutorial

Source: Internet
Author: User
Differences between php functions mysql_fetch_row, assoc, array, and object. Differences between php functions mysql_fetch_row, assoc, array, and object 1. mysql_fetch_row is used to retrieve a row from the result set as Enumeration data, differences between the php function mysql_fetch_row, assoc, array, and object associated with the specified result identifier

1. mysql_fetch_row

This function extracts a row from the result set as Enumeration data, and obtains a row of data from the result set associated with the specified result ID and returns the data as an array. Each result column is stored in an array unit, and the offset starts from 0.

Note: Here the offset starts from 0. that is to say, the field name cannot be used for the value, but the index can only be used for the value. For example:

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

Echo $ row ['CID']. '>>>'. $ row [1].'
';

}

$ Row ['CID'] cannot be obtained here, and $ row [1] can be obtained.

II. mysql_fetch_assoc

Retrieve a row from the result set as an associated array. that is to say, this function cannot be indexed as mysql_fetch_row, and can only be retrieved using field names. For example:

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

Echo $ row ['CID']. '>>>'. $ row [1].'
';

}

Here, $ row [1] cannot obtain the value. $ row ['CID'] can obtain the value.

III. mysql_fetch_array

Obtain a row from the result set as an associated array or number array, or both. in addition to storing data in the array as a digital index, you can also store the data as an associated index, use the field name as the key name.

That is to say, the result obtained by him is like an array. he can use keys or indexes to take values. 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.

IV. 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 only in this way can we get the value:

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

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

}

Distinct 1. the mysql_fetch_row function extracts a row from the result set as Enumeration Data and associates the row with the specified result ID...

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.