The function of this code is to connect to a mysql server whose url address is localhost and Port is 3306. The function of this code in mysql server is to connect to a mysql server with a url address of localhost and Port 3306. The account and password of the mysql server are "root" and "9999 ". The mysql server has a database "OK" and a table "abc" in the database. The abc table has two columns: "id" and "name ".
The functions of this code are as follows:
Connect to a mysql server whose url is localhost and Port is 3306. The account and password of the mysql server are "root" and "9999 ". There isDatabaseOK,DatabaseThere is a table abc. The abc table has two columns: "id" and "name". The column names read all the data in abc.
Reference content is as follows:
$ Dbh = @ mysql_connect ("localhost: 3306", "root", "9999 "); /* Defines the variable dbh. the mysql_connect () function means to connect to mysql.Database, "@" Means blocking error reporting */ If (! $ Dbh) {die ("error ");} /* The die () function means to send the strings in brackets to the browser and interrupt the PHP program (Script ). The parameters in the brackets are the strings to be sent. */ @ Mysql_select_db ("OK", $ dbh ); /* Select one of the mysql serversDatabase, Selected hereDatabaseName: OK */ $ Q = "SELECT * FROM abc"; Web teaching network http://www.webjx.com /* Define the variable q. "SELECT * FROM abc" is an SQL statement that reads data in table abc */ ?>
$ Rs = mysql_query ($ q, $ dbh ); /* Define the rs variable. the Function mysql_query () indicates that the query string is sent for MySQL to perform related processing or execution. since php is executed from right to left, the rs value is the value returned after the server runs the mysql_query () function */ If (! $ Rs) {die ("Valid result! ");} Echo"
";Echo"
ID |
Name |
";While ($ row = mysql_fetch_row ($ rs) echo"
$ Row [0] |
$ Row [1] |
";/* Define the volume change (array) row and write the data one by one using the while loop.The mysql_fetch_row () function means to split the query result $ rs into an array variable.$ Row [0] and $ row [1] can be changed */Echo"
"; ?>
$ Rs = mysql_query ($ q, $ dbh ); While ($ row = mysql_fetch_object ($ rs) echo "$ row-> id $ row-> name "; /* The id and name can be changed */ ?>
$ Rs = mysql_query ($ q, $ dbh ); While ($ row = mysql_fetch_array ($ rs) echo "$ row [id] $ row [name] "; /* The id and name can be changed */ ?> @ Mysql_close ($ dbh ); /* Close to mysqlDatabase*/ ?> |