After login, it is like this: first, we 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 in it. Next, I implemented a function: connect to the database and print out the table content. Connect data... "/> <scripttype =" text/javascript "src =" http ://
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]
$ 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! ";
?>
$ 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]
Include ("conn. php ");
$ SQL = "select * from items ";
$ Query = mysql_query ($ SQL );
Echo"
Id |
Name |
";While ($ row = mysql_fetch_array ($ query )){$ Id = $ row ["id"];$ Name = $ row ["name"];Echo"
". $ Id ." |
". $ Name ." |
";}Echo"
";
Mysql_close ();
?>
Include ("conn. php ");
$ SQL = "select * from items ";
$ Query = mysql_query ($ SQL );
Echo"
Id |
Name |
";While ($ row = mysql_fetch_array ($ query )){$ Id = $ row ["id"];$ Name = $ row ["name"];Echo"
". $ Id ." |
". $ Name ." |
";}Echo"
";
Mysql_close ();
?>
Close the job.