PHP MySQL database operations can be divided into five general steps: connecting a MySQL database server; Select Database 2; 3 execute SQL statements; 4 result set is closed; 5 disconnected from the MySQL database server.....
1. mysql_connect () function to connect MySQL database server
() Function establishes a connection with the server with mysql_connect. The return value is then positioned different connection functions.
Host = $ "localhost" ; // MySQL server address
the User = $ "root" ; // username
pwd = $ "***" ; // Password
$ ConnID = mysql_connect ($ host, $ user, $ pwd); // return a connection identifier
2. mysql_select_db () function to select a database file
With the mysql_select_db () function returns the first step of a connection identifier database selected
mysql_select_db ( $ dbName , $ ConnID ); // $ dbName said to be the database of choice
() Function executes SQL statements 3. mysql_query
The first step: mysql_query ( "the SELECT * from tb_stu", $ ConnID ); // execute the query returns a result set
Step Two: acquiring focus information from the above results, there are two paths. 1. the mysql_fetch_array () function set information acquired from the array results; 2 () function to obtain a result set from a line mysql_fetch_object as an object. The difference is that mysql_fetch_object () return value is an object, not an array, that is, the function can only be accessed by an array of field names.
$result = mysql_fetch_array($query);
OR
$result = mysql_fetch_object($query);
The general operation of the data following five types:
1. The query data (select)
The display data (select)
3. Insert data (insert)
4. Update data (Update)
5. Delete Data (delete)
4. Close the result set
After the operation is complete database needs to close the result set, the release of resources
mysql_free_result($result);
5. disconnect from a server
Each use mysql_connect () or mysql_query () function, will consume system resources, in order to avoid waste of resources, with mysql_close () function to close the connection MySQL server, to conserve system resources.
mysql_close($connID);
Reproduced in: https: //www.cnblogs.com/AI-Algorithms/p/4305054.html