PHPmysql_fetch_array () function _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Explore PHPmysql_fetch_array () in depth. We all know that if the function is successfully executed, it will get a row of information (this row is obtained by executing the mysql_query () function) and return the row information; if it fails, no information will be returned,

If the function is successfully executed, it obtains a row of information (this row is obtained by executing the mysql_query () function) and returns the Row Information. if the function fails, no row is returned.

PHP mysql_fetch_array () function syntax

Mysql_fetch_array (data, array_type)

Data is a required parameter and specifies the data pointer [data pointer] to be used. The data pointer is returned by requesting the mysql_query () function.

Array_type is an optional parameter. Specifies the type of the returned array. The optional parameters are as follows:

* MYSQL_ASSOC-associated array [Associative array]
* MYSQL_NUM-Numeric array [Numeric array]
* MYSQL_BOTH-default value. Include correlated array [Associative array] and Numeric array [Numeric array]

PHP mysql_fetch_array () function tips and notes

Note: after the specified data is obtained, the function points to the next record. if you continue to request the mysql_fetch_array () function, the next record is returned.

Tip: The field names returned by the mysql_fetch_array () function are case insensitive.

PHP mysql_fetch_array () function case

 
  1. < ?php
  2. $con = mysql_connect("localhost",
    "peter", "abc123");
  3. if (!$con)
  4. {
  5. die('Could not connect: ' .
    mysql_error());
  6. }
  7. $db_selected = mysql_select_db
    ("test_db",$con);
  8. $sql = "SELECT * from Person
    WHERE Lastname='Refsnes'";
  9. $result = mysql_query($sql,$con);
  10. print_r(mysql_fetch_array($result));
  11. mysql_close($con);
  12. ?>

The above code will output the following results:

 
  1. Array
  2. (
  3. [0] => Refsnes
  4. [LastName] => Refsnes
  5. [1] => Kai Jim
  6. [FirstName] => Kai Jim
  7. [2] => Taugata 2
  8. [Address] => Taugata 2
  9. [3] => 22
  10. [Age] => 22
  11. )

The above describes how to use the PHP mysql_fetch_array () function.


If the function is successfully executed, it obtains a row of information (this row is obtained by executing the mysql_query () function) and returns the Row Information. if the function fails, no information is returned...

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.