PHP mysql_fetch_array () function

Source: Internet
Author: User
Definition and usage

The mysql_fetch_array () function retrieves a row from the result set as an associated array, or an array of numbers, or both.

Returns the array generated based on the rows obtained from the result set. If no more rows exist, false is returned.

Syntax
mysql_fetch_array(data,array_type)
Parameters Description
Data Optional. Specifies the Data Pointer to be used. This Data Pointer is produced by the mysql_query () function.
Array_type

Optional. Specifies the result to be returned. Possible values:

  • Mysql_assoc-associated array
  • Mysql_num-number Array
  • Mysql_both-default. Generate join and numeric arrays at the same time
Tips and comments

Note: mysql_fetch_array () is an extended version of mysql_fetch_row. In addition to storing data in an array as a digital index, you can also store data as an associated index and use the field name as the key name.

Note: It is important to note that mysql_fetch_array () is not significantly slower than mysql_fetch_row (), and more values are obviously provided.

Note: The field names returned by this function are case sensitive.

Example
<?php$con = mysql_connect("localhost", "hello", "321");if (!$con)  {  die('Could not connect: ' . mysql_error());  }$db_selected = mysql_select_db("test_db",$con);$sql = "SELECT * from Person WHERE Lastname='Adams'";$result = mysql_query($sql,$con);print_r(mysql_fetch_array($result));mysql_close($con);?>

The output is similar:

Array([0] => Adams[LastName] => Adams[1] => John[FirstName] => John[2] => London[City] => London) 

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.