PHP access to query MySQL data common three ways

Source: Internet
Author: User
Tags php tutorial
PHP access to query MySQL data commonly used three ways:

1. $row = Mysql_fetch_row ($result);

Returns an array of rules $row, $row [0] is the first element, $row [1] is the second element, and so on ...
Mysql_num_fields ($result) returns the number of elements of the result.

2. $row = Mysql_fetch_array ($result);

Returns an array of $row. Examples are as follows:
The table structure is as follows:

Username | PassWord
-------------------------------------
Bourbon | Abc
Berber | Efg

The first run $row = mysql_fetch_array ($result) results in the following:

$row [0] = $row ["username"] = "Bourbon"
$row [1] = $row ["password"] = "abc"

The first run $row = mysql_fetch_array ($result) results in the following:

$row [0] = $row ["username"] = "Berber"
$row [1] = $row ["password"] = "EFG"


3. $row = Mysql_fetch_object ($result);

Returns an object description row. As in the above example
The first run of run $row = mysql_fetch_object ($result) results in the following:

$row->username = "Bourbon"
$row->password = "abc"

The second run of run $row = mysql_fetch_object ($result) results in the following:
$row->username = "Berber"
$row->password = "EFG"

The above describes the PHP access to query MySQL data commonly used three methods, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    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.