Differences between mysql_fetch_array () and mysql_fetch_rows () functions in php

Source: Internet
Author: User


Mysql_fetch_array () function parameters

The mysql_fetch_array () function retrieves a row from the result set as an associated array, or an array of numbers, or both.
Returns the array generated based on the rows obtained from the result set. If no more rows exist, false is returned.

Mysql_fetch_array (data, array_type)

Array_type is as follows:

MYSQL_ASSOC-associated array
MYSQL_NUM-number array
MYSQL_BOTH-default. Generate join and numeric arrays at the same time

Mysql_fetch_rows () function parameters

The mysql_fetch_row () function retrieves a row from the result set as a numeric array.

Mysql_fetch_row (data)

From the above, they are all data pointers used. This data pointer is generated by the mysql_query () function, but there is a different parameter later. mysql_fetch_array () has the array_type parameter while mysql_fetch_rows () does not.

So what are the differences in usage? Let's take a look at the example below.

Both mysql_fetch_array () and mysql_fetch_rows () can obtain the field data of the database. For details about the differences, refer to the instance organized by www.111cn.net:

Example of the mysql_fetch_array () function

<? Php

$ SQL = "select * from user";

$ Query = mysql_query ($ SQL );

$ Result = mysql_fetch_array ($ query );

Echo $ result [name];

Echo $ resutlt [password];

?>

Example of mysql_fetch_rows () function

<? Php

$ SQL = "select * from user";

$ Query = mysql_query ($ SQL );

$ Result = mysql_fetch_rows ($ query );

Echo $ result [1];

Echo $ resutlt [2];

?>

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.

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.