PHP Database result set processing

Source: Internet
Author: User

After the MySQL connection is successful, you can use Msql_query to obtain a resource-based result set.

$sql = ' select * from Emp_info ';
$result = mysqli_query ($link, $sql);

You can then use functions such as MYSQL_FETCH_ASSOC (), Mysql_fetch_row (), mysql_fetch_array (), mysql_fetch_object () to work with the result set.

The purpose of the MYSQL_FETCH_ASSOC () function is to obtain a row of data from the result set and return it as an associative array whose "key" is the field name of the data table, and "value" is the data for that field. When MYSQL_FETCH_ASSOC () executes successfully, it is automatically moved to the next row of the result set to continue reading until all the data has been read.
$emp _info = Array ();
while ($row = Mysqli_fetch_assoc ($result)) {
$emp _info[] = $row;
}

The function of the mysql_fetch_row () function is to read a row of data from the result set and return it as an indexed array. The method of declaration is the same as Assoc.
The array function returns the result in the form of an indexed array and an associative array, respectively.
object is similar to an array, except that it returns an object instead of an array, and only accesses the data through the word by.

PHP Database result set processing

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.