Steps for accessing a database interaction using PHP: 1. open the database connection mysql_pconnect (host, user name, password); for example: $ useName & quot; root & quot; $ passwd & quot; yb & quot; $ Sserver & quot; wagner. 0.0.1: 3306 & quot; $ db_link @ mysql_connect
The procedure for accessing a database interaction with PHP is as follows:
1. open the database connection
Mysql_pconnect (host, user name, password );
For example:
$ UseName = "root ";
$ Passwd = "yb ";
$ Sserver = "127.0.0.1: 3306 ";
$ Db_link = @ mysql_connect ($ Sserver, $ useName, $ passwd );
2. select an active database
$ Db = mysql_select_db ("$ dbname ")
Example: $ bresult = mysql_select_db (myphp, $ db_link );
3. perform the query operation:
Mysql_query ($ SQL)
Example: mysql_query ("select * from student", $ db_link );
4. get the number drama from the result:
$ Row = mysql_fetch_array ($ rst) or die ("no more records! "); // Retrieve a record
Example: $ row = mysql_fetch_row ($ result)
5. release memory resources
Mysql_free_result ($ rst) or die ("The result resource cannot be released! ");
Example: mysql_free_result ($ result)
6. shut down the database
@ Mysql_close ($ db_link );
Example of the entire process:
$ UseName = "root ";
$ Passwd = "yb ";
$ Sserver = "127.0.0.1: 3306 ";
$ Db_link = @ mysql_connect ($ Sserver, $ useName, $ passwd );
$ Bresult = mysql_select_db (myphp, $ db_link );
$ Result = mysql_query ("select * from student", $ db_link );
$ I = 0;
While ($ row = mysql_fetch_row ($ result ))
{
Print_r ("id =". $ row [0]. "$ nbsp; name =". $ row [1]."
");
$ I ++;
}
Mysql_data_seek ($ result, 0 );
Mysql_free_result ($ result );
Print ("$ I ");
@ Mysql_close ($ db_link );
?>
Author: "ITeamsky-Yang Bo's technical space"