4 MySQL connection with PHP

Source: Internet
Author: User

Directory:

1. Connection overview
2. Create a php file for MySQL connection
3. View the connection effect

1. Connection overview

The lamp development model is described above and is installed using Appserv. This is the time to embody the advantages. This section describes the data that is read in the MySQL database directly using PHP and is displayed in the browser.

2. Create a php file for MySQL connection

Enter the Appserv installation directory, this machine is in D:\Program files\appserv, enter the WWW directory, in this new folder school, and in the school folder under the new index.php file, and enter the following code in the file, save close.

1<?PHP2 //Connect to the database, select3 $conn=mysql_connect("localhost", "root", "password");//password change to the root account password set when installing Appserv4 $result=Mysql_db_query("Schooldb", "SELECT * from Student",$conn);5  6 //Get query Results7 $row=Mysql_fetch_row($result);8 Echo' <font face= ' Verdana ' > ';9 Echo' <table border= ' 1 "cellpadding=" 1 "cellspacing=" 2 "> ';Ten  One //Show Field names A Echo"</b><tr></b>"; -  for($i= 0;$i<Mysql_num_fields($result);$i++) - { the     Echo' <td><b> '. -     Mysql_field_name($result,$i); -     Echo"</b></td></b>"; - } +  - Echo"</tr></b>"; + //Navigate to the first record A Mysql_data_seek($result, 0); at //Loop Out Records -  while($row=Mysql_fetch_row($result)) - { -     Echo"<tr></b>"; -      for($i= 0;$i<Mysql_num_fields($result);$i++ ) -     { in         Echo' <td> '; -         Echo $row[$i]; to         Echo' </td> '; +     } -     Echo"</tr></b>"; the } *  $ Echo"</table></b>";Panax Notoginseng Echo"</font>"; -  the //Freeing Resources + Mysql_free_result($result); A //Close Connection the Mysql_close($conn);  +?>
View Code

3. View the connection effect

Enter localhost/school/in the browser to see the following.

4 MySQL connection to PHP

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.