After landing it was like this:
Let's start by creating a database for testing.
Lazy words can be created directly in the phpMyAdmin.
I created a books database with a table of item:
Next, implement a function: Connect to the database and print out the contents of the table.
Connecting to a 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 will display 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 ();
?>
Finish the call.
http://www.bkjia.com/PHPjc/477590.html www.bkjia.com true http://www.bkjia.com/PHPjc/477590.html techarticle after landing it's like this: first we create a database for testing. Lazy words can be created directly in the phpMyAdmin. I created a books database with ...