Several ways to convert MySQL query results to PHP arrays

Source: Internet
Author: User
Tags mysql query
This article is mainly to share with you several MySQL query results converted to PHP array method, mainly in the form of text and we share, hope to help everyone.

$result = Mysql_fetch_row (): This function returns an array of numbers as subscripts, which you can only refer to in the form of $result[0], $Result [2].

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

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

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

It is recommended to use MYSQL_FETCH_ASSOC () or mysql_fetch_array, which performs faster and can also be referenced by field names, which is relatively clear.

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.