The usage and difference of fetch in php query data

小云云
Release: 2023-03-21 20:30:02
Original
5535 people have browsed it


  • This article mainly shares with you the usage and differences of fetch for PHP query data. There are four kinds of fetch usage and differences. I hope it can help everyone.

  • mysql_fetch_row;

  • mysql_fetch_array;

  • mysql_fetch_assoc;

  • mysql_fetch_object;

1.mysql_fetch_row;

Every time mysql_fetch_row is executed, a piece of data is taken out from the resource result set. Return it as an array.

#The returned array is a one-dimensional index array, and each subscript corresponds to the sorting of the fields in the database.


##2.mysql_fetch_array();

The difference between mysql_fetch_array and mysql_fetch_row:
1, mysql_fetch_row is executed once to generate an index array;
2, mysql_fetch_array is in the default state Take a piece of data to generate an index array and associative array

/********
mysql_fetch_array has a second parameter
1, MYSQL_ASSOC -Associative array
2. MYSQL_NUM - Numeric array (index array)
3. MYSQL_BOTH - Default state (both index array and associative array are displayed) **************/

Default state The index array and associative array are displayed below


##3.mysql_fetch_assoc();

Only display associative arrays


##4, mysql_fetch_object

The displayed data is an object.


##When fetching the data of a single attribute: echo $row->name;

Related recommendations:

Detailed explanation of PHP’s mysql_fetch series functions

The above is the detailed content of The usage and difference of fetch in php query data. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template