The MySQL extension library operates the MySQL database in the following steps:
1: Get the connection.
2: Choose the Library.
3: Set the action encoding.
4: Send SQL instructions (MySQL database can be divided into four kinds of instructions:
1:DDL: Data definition language.
2:DML: Data manipulation language (e.g. curd);
3:DQL: Data Query Language. (such as Select)
4:DTL: Data things language.
)。
5: Receive the returned result and process.
6: Disconnect.
The specific sample code is as follows:
<pre name= "code" class= "PHP" ><pre name= "code" class= "PHP" ><pre name= "code" class= "PHP" ><?php// 1: Connect database $con=mysql_connect ("localhost", "root", "Toor");//If there is no successful connection to error if (! $con) {echo "Connection failed"; exit ();} 2: Select the database to operate mysql_select_db ("test");//3: Send SQL Instruction mysql_query ("Set names UTF8");//Set query encoding $sql= "SELECT *from test1"; $ Res=mysql_query ($sql, $con);//4: Returns the result (returned by row traversal) while ($row =mysql_fetch_row ($res)) {echo "$row [0]-------------$row [1]- ----------$row [2]-----------$row [3]-----------$row [4] "." <br/> ';} 5: Release resources, close connection mysql_free_result ($res); Mysql_close ($con);? >
To illustrate, all of the operations here are in the memory of the operation, can not be taken for granted is what things, so say, understand some of the underlying things still have certain benefits.
MySQL and PHP connection operation points