Post Code First
The code is as follows:
<title> Database Related </title>
<body>
<?php
$con = mysql_connect ("localhost", "root", "root"); Link Database
if (! $con) {
Die (' Connection failed! ' . Mysql_error ()); To judge whether or not to succeed
}
/* IF (mysql_query ("CREATE DATABASE testdb", $con)) {//mysql_query query or Send command
echo "Create TestDB success";
}
else{
echo "Reason for failure:". Mysql_error (); To determine whether a success was created
}
*/
mysql_select_db ("TestDB", $con); Select the database that the link just created
$sql = "CREATE TABLE Persons
(PersonID int not NULL auto_increment,
PRIMARY KEY (PersonID),
FirstName varchar (15),
LastName varchar (15),
Age int)
"; Mysql Statement Creation Table
mysql_query ($sql, $con); Execute SQL statement
Mysql_close ($con); Close MySQL Connection
?>
</body>
The key element is
1, linked to the database
2. Create a table
3, according to the needs of the table content to enrich
The above is the entire content of this article, I hope that the small partners can enjoy.