In php, mysql_fetch_assoc (), mysql_fetch_array (), mysql_fetch_row (), and mysql_fetch_object

Source: Internet
Author: User
In php, mysql_fetch_assoc (), mysql_fetch_array (), mysql_fetch_row (), and mysql_fetch_object
This article introduces the usage differences of mysql operation functions mysql_fetch_assoc (), mysql_fetch_array (), mysql_fetch_row (), and mysql_fetch_object () in php. For your reference.

Similarities: all three functions return a row of data (that is, a row of data) queried in the database ). Difference: mysql_fetch_assoc () uses the key value (that is, the array subscript) of the corresponding field name in the database, for example, filed ['id'] = 1;

Mysql_fetch_row () uses the automatically generated number (generated from 0 in turn) as the key value (that is, the array subscript), for example: filed [0] = 1; mysql_fetch_array () it uses the automatically generated number (generated from 0 in turn) as the key value (that is, the array subscript ), in addition, it also generates the corresponding field names in the database as the key value (that is, the array subscript ).

For example, filed [0] = 1, filed ['id'] = 1; that is, mysql_fetch_array () integrates the results queried by mysql_fetch_assoc () and mysql_fetch_row. Mysql_fetch_object () is similar to mysql_fetch_assoc. Only the array returned by mysql_fetch_assoc. Mysql_fetch_object () returns the object.

We hope that you will carefully understand the comparison and analysis above, so as to better understand their differences and specific application scenarios.

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.