Distinguish between mysql_fetch_array () and mysql_fetch_rows () functions

Source: Internet
Author: User

Form:http://www.uphtm.com/php/254.html

If we do not look closely will find like mysql_fetch_array () and mysql_fetch_rows () function There is no difference, but look at you will find that they are still very big difference, if you do not understand the difference between the following small series for you to organize Mysql_ Use and examples of Fetch_array () and Mysql_fetch_rows ().

Mysql_fetch_array () function parameters

The Mysql_fetch_array () function takes a row from the result set as an associative array, or as a numeric array, or both
Returns an array based on the rows obtained from the result set, or False if there are no more rows.

Mysql_fetch_array (Data,array_type)

Array_type as follows

MYSQL_ASSOC-Associative arrays
Mysql_num-numeric array
Mysql_both-Default. Simultaneous generation of associative and numeric arrays

Mysql_fetch_rows () function parameters

The Mysql_fetch_row () function takes a row from the result set as a numeric array.

Mysql_fetch_row (data)

From the above, they are all data pointers used. The data pointer is the result of the mysql_query () function, but there is a different parameter behind it, and Mysql_fetch_array () has a array_type parameter and mysql_fetch_rows () does not.

So what's the difference in usage, here's an example

Mysql_fetch_array () and mysql_fetch_rows () can get the field data of the database, the specific differences can be referenced to the collation of the instance:

Mysql_fetch_array () Function Example

    1. <?php
    2. $sql = "SELECT * from user";
    3. $query =mysql_query ($sql);
    4. $result =mysql_fetch_array ($query);
    5. echo $result [name];
    6. echo $resutlt [password];
    7. ?>

Mysql_fetch_rows () Function Example

    1. <?php
    2. $sql = "SELECT * from user";
    3. $query =mysql_query ($sql);
    4. $result =mysql_fetch_rows ($query);
    5. echo $result [1];
    6. Echo $RESUTLT [2];
    7. ?>

In summary, Mysql_fetch_array () is an array and can be associated with an array, while Mysql_fetch_rows is an object that cannot be associated with an array, the difference is here.

Form:http://www.uphtm.com/php/254.html

Distinguish between mysql_fetch_array () and mysql_fetch_rows () functions

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.