Operation points for connecting MySQL data with PHP
The steps for the MySQL extension library to operate the MySQL database are as follows:
1: Get connection.
2: Select the library.
3: Set the operation code.
4: Send SQL commands (MySQL database can be divided into four commands:
4.1: ddl: Data Definition Language.
4.2: dml: data manipulation language (such as CURD);
4.3: dql: data query language. (Such as select)
4.4: dtl: Data Transaction Language.
5: Receive the returned result and process it.
6: Disconnect.
The specific sample code is as follows:
The code is as follows:
//1: Connect to database
$con=mysql_connect("localhost","root","toor");
//If the connection is not successful, an error will be reported
if(!$con){
echo "Connection failed";
exit();
}
//2: Select the database to operate
mysql_select_db("test");
//3:Send SQL command
mysql_query("set names utf8");//Set query encoding
$sql="select *from test1";
$res=mysql_query($sql,$con);
//4: Return results (traverse and return by row)
while($row=mysql_fetch_row($res)){
echo "$row[0]-------------$row[1]----------$row[2]--------- --$row[3]-----------$row[4]".'
';
}
//5: Release resources and close the connection
mysql_free_result($res);
mysql_close($con);
?>
It should be noted that all operations here are performed in memory, and nothing can be taken for granted. Therefore, it is still beneficial to understand some low-level things.
http://www.bkjia.com/PHPjc/971948.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/971948.htmlTechArticleOperation points of PHP connecting to MySQL data. The steps for the MySQL extension library to operate the MySQL database are as follows: 1: Obtain the connection. 2: Select a library. 3: Set the operation code. 4: Send SQL command (MySQL data...