php SQL query returns the array method: 1. Use the mysql_fetch_row function; 2. Through the mysql_fetch_assoc function; 3. Use the mysql_fetch_array function; 4. Use the mysql_fetch_object function.
Recommended: "PHP Video Tutorial"
Several ways to convert mysql query results into PHP arrays The difference between methods
$result = mysql_fetch_row(): This function returns an array. The array is subscripted with numbers. You can only pass $result[0],$Result[2] like this citation form.
$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 $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 How to return array in php sql query. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version
Useful JavaScript development tools
