Php code for querying mysql data table records

Source: Internet
Author: User
Php and mysql are prime combinations. now let's talk about how to query mysql database records in php. the Function mysql_connectmysql_querymysql_select_dbmysql... php and mysql are prime combinations. now let's talk about the implementation of querying mysql database records in php. the Function mysql_connect mysql_query mysql_select_db mysql_fetch_array is mainly used. The following describes the implementation.

 Www. phprm. comn "; echo" name: ". $ rows [name]; echo"
N "; echo" sex: ". $ rows [sex]; echo"
N "; echo" birthday: ". $ rows [birthday]; echo"
N "; echo" address: ". $ rows [address]; echo"

N ";} // release the result set mysql_free_result ($ result); // query the condition $ query =" select * from friends where id = 1 "; // define SQL $ result = mysql_query ($ query); // send the SQL query echo mysql_result ($ result, 0, "name"); // output the name result echo"
"; Echo mysql_result ($ result, 0," birthday "); // output the birthday result echo"
"; Echo mysql_result ($ result, 0," sex "); // output sex result echo"
"; Echo mysql_result ($ result, 0," address "); // output address results // related operations $ conn = mysql_connect ('localhost', 'root ', ''); // open the connection $ fields = mysql_list_fields (" test "," friends ", $ conn ); // list the information of the test database friends table $ cols = mysql_num_fields ($ fields); // Obtain the number of results for ($ I = 0; $ I <$ cols; $ I ++) // loop {echo mysql_field_name ($ fields, $ I ). "n"; // output field name echo"

";}

Summary: It is quite simple and common to query database records in php. you can query data as long as you record the above functions.


Address:

Reprinted at will, but please attach the article address :-)

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.