Key points for connecting MySQL data with PHP, key points for phpmysql data_PHP tutorial

WBOY
Release: 2016-07-13 10:01:57
Original
1121 people have browsed it

Operation points for PHP to connect to MySQL data, phpmysql data points

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:
Copy code 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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/970991.htmlTechArticleOperation points for PHP to connect to MySQL data, phpmysql data points. The steps for the MySQL extension library to operate the MySQL database are as follows: 1: Obtain Link. 2: Select the library. 3: Set the operation code. 4: Send...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!