PHP-Working with the Select query result set in a PHP script

Source: Internet
Author: User

Executing a SELECT query command in a PHP script is also called the mysql_query () function, but unlike executing DML, the return value of the mysql_query () function is a reference pointer (result set) of a resource after the Select command is executed. It needs to be handled by the corresponding function.

Mysql_num_rows ($result) Get the number of data records from the result set

Mysql_num_fields ($result) Get the number of data record columns from the result set

Mysql_fetch_row () The function returns a result record and saves it as a normal indexed array

MYSQL_FETCH_ASSOC () The function returns a result record and saves it as a normal associative array

Mysql_fetch_array () is saved by default at the same time as an indexed array and an associative array, three parameters Mysql_assoc, Mysql_num, Mysql_both

Mysql_fetch_object () Returns a result record in the form of an object whose fields need to be accessed as objects

Note: Try not to use the Mysql_fetch_array () method, less efficient

<?PHP$link=mysql_connect(' localhost ', ' root ', ' abc123 '); if(!$link){         die(' Database link failed: '.Mysql_error()); }    mysql_select_db(' Test '); $select= "SELECT * from book;"; $result=mysql_query($select); Echo"<table align= ' center ' width= ' 60% ' border= ' 1 ' >"; Echo' <caption>; Echo' <th> book number </th><th> book name </th><th> author </th> ';  while($row=Mysql_fetch_row($result)){        Echo"<tr>"; foreach($row  as $data){            Echo' <td> '.$data.‘ </td> '; }        Echo' </tr> '; }    Echo"</table>"; Mysql_free_result($result);//to free the result set resource for a query    Mysql_close($link);?>

PHP-Working with the Select query result set in a PHP script

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.