数据库_连接数据库_创建数据库——创建表——增加记录
<html>
<head>
<title>test</title>
</head>
<body>
//连接数据库
$con = mysql_connect("localhost","root","123456");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// 创建数据库
//Create database
if (mysql_query("CREATE DATABASE my_shujuku",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}
//创建表
//Create table in my_db database
mysql_select_db("my_shujuku", $con);
$sql = "CREATE TABLE Persons
(
FirstName varchar(15),
LastName varchar(15),
Age int
)";
mysql_query($sql,$con);
//像表中添加记录
mysql_query("INSERT INTO Persons (FirstName, LastName, Age)
VALUES ('Glenn', 'Quagmire', '33')");
mysql_query("INSERT INTO Persons (FirstName, LastName, Age)
VALUES ('Glenn', 'Quagmire', '33')");
//关闭数据库
mysql_close($con);
?>
</body>
</html>