After login, it is like this:
First, create a database for testing.
If you are lazy, you can create it directly in phpMyAdmin.
I created a books database with an item table:
Next, we will implement a function: connect to the database and print out the table content.
Connect to database
[Php]
<? Php
$ Db_host = 'localhost ';
$ Db_user = 'root ';
$ Db_pass = '1 ';
$ Db_name = 'books ';
$ Conn = mysql_connect ($ db_host, $ db_user, $ db_pass)
Mysql_select_db ($ db_name, $ conn );
Mysql_query ("set names 'utf8 '");
If (! $ Conn) echo "failed! ";
Else echo "success! ";
?>
<? Php
$ Db_host = 'localhost ';
$ Db_user = 'root ';
$ Db_pass = '1 ';
$ Db_name = 'books ';
$ Conn = mysql_connect ($ db_host, $ db_user, $ db_pass)
Mysql_select_db ($ db_name, $ conn );
Mysql_query ("set names 'utf8 '");
If (! $ Conn) echo "failed! ";
Else echo "success! ";
?>
If the connection is normal, the browser displays seccess!
Create list. php
[Php]
<? Php
Include ("conn. php ");
$ SQL = "select * from items ";
$ Query = mysql_query ($ SQL );
Echo "<table border = 1> <tr> <td> Id </td> <td> Name </td> </tr> ";
While ($ row = mysql_fetch_array ($ query ))
{
$ Id = $ row ["id"];
$ Name = $ row ["name"];
Echo "<tr> <td>". $ id. "</td> <td>". $ name. "</td> </tr> ";
}
Echo "</table> ";
Mysql_close ();
?>
<? Php
Include ("conn. php ");
$ SQL = "select * from items ";
$ Query = mysql_query ($ SQL );
Echo "<table border = 1> <tr> <td> Id </td> <td> Name </td> </tr> ";
While ($ row = mysql_fetch_array ($ query ))
{
$ Id = $ row ["id"];
$ Name = $ row ["name"];
Echo "<tr> <td>". $ id. "</td> <td>". $ name. "</td> </tr> ";
}
Echo "</table> ";
Mysql_close ();
?>
Close the job.