Several ways to convert mysql query results into PHP arrays

小云云
Release: 2023-03-22 21:10:01
Original
2701 people have browsed it

This article mainly shares with you several methods of converting mysql query results into PHP arrays. It is mainly shared with you in text form. I hope it can help you.

$result = mysql_fetch_row(): This function returns an array. The array is subscripted with numbers. You can only reference it in the form of $result[0], $Result[2].

$result = mysql_fetch_assoc(): This function returns an array subscripted by the field name, which can only be referenced by the field name.

$result['field1']. $result = mysql_fetch_array(): This function returns a mixed array that can be referenced either by numeric subscript or by field name.

$result[0] or $result["field1"]. $result = mysql_fetch_object(): Returns the result in the form of an object, which can be referenced in the form of $result->field1.

It is recommended to use mysql_fetch_assoc() or mysql_fetch_array. These two functions execute faster and can also be referenced through field names, which is clearer.

The above is the detailed content of Several ways to convert mysql query results into PHP arrays. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!