Php connection to MySQL database operations and application code

Source: Internet
Author: User

The following articles mainly introduce the actual operation process of connecting php to the MySQL database, as well as the description of the Code needed for actual operations, the following article describes the actual procedure of connecting php to the MySQL database and the actual application code.

 
 
  1. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 

PHP for MySQL

Open extension = php_MySQL.dll

 
 
  1. <?php 
  2. $servername = "127.0.0.1";  
  3. $username = "root";  
  4. $password = "123456";  
  5. $conn = MySQL_connect($servername, $username, $password);  

Create a MySQL connection

 
 
  1. If ($ conn ){
  2. Echo "connection successful ";
  3. }
  4. // MySQL_select_db ("easytoo ");

Select to connect to the MySQL database

Or

 
 
  1. MySQL_query("use easytoo",$conn); 

Select to connect to the MySQL database

 
 
  1. MySQL_query("SET NAMES utf8");  
  2. $rs = MySQL_query("select id from et_category"); 

Query and obtain a dataset

 
 
  1. MySQL_num_rows($rs);  

Obtain the total number of record sets.

 
 
  1. while($row= mysql _fetch_array($rs))  

Cyclic Dataset

 
 
  1. {  
  2. echo "$row[0]<br>";  
  3. }  
  4. mysql_free_result($rs);  

Release rs

 
 
  1. mysql_close($conn); 

Close connection

 

 
 
  1. ?> 

The above content is an introduction to the connection of php to the MySQL database. I hope you will have some gains.

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.