Delve into PHP mysql_fetch_array () Functions _php Tutorial

Source: Internet
Author: User
As we all know,

If the function executes successfully, it gets a line of information (which is obtained by executing the mysql_query () function) and returns the row information, and if it fails, no row is returned.

PHP mysql_fetch_array () function syntax

Mysql_fetch_array (Data,array_type)

The data is the necessary parameter, specifying the need to use the pointer to the pointer. The data pointer is returned by requesting the mysql_query () function.

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

* mysql_assoc– associative array [associative array]
*mysql_num– numeric array [Numeric array]
* mysql_both– default value. Contains associative array [associative array] and numeric array [Numeric array]

PHP mysql_fetch_array () function hints and note points

Note: When the specified data is fetched, the function will point to the next record, and if you continue to request the Mysql_fetch_array () function then the next record will be returned.

Tip: The field names returned by the mysql_fetch_array () function do not differentiate between letter case.

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 code above will output the following result:

 
  
  
  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] =>
  10. [age] = > a
  11. )

These are the specific uses of the PHP mysql_fetch_array () function.


http://www.bkjia.com/PHPjc/446052.html www.bkjia.com true http://www.bkjia.com/PHPjc/446052.html techarticle as we all know, if the function executes successfully, it will fetch a line of information (the line is obtained by executing the mysql_query () function) and return the line information, and if it fails, it will not return any ...

  • 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.