<meta charset="UTF-8">
<!-- 1 数据库的创建-->
<?php
/*
* Created by PhpStorm.
* User: admirtor
* Date: 2018/2/12
* Time: 13:19
*/
$servername = "localhost";
$username = "root";
$password = "root";
// 创建连接
$conn = new mysqli($servername, $username, $password);
// 检测连接
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
// 创建数据库$sql = "CREATE DATABASE myDB";
if ($conn->query($sql) === TRUE) {
echo "数据库创建成功";
} else {
echo "Error creating database: " . $conn->error;
}
$conn->close();
?><!--2 创建数据表--><?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "myDB";
// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);// 检测连接
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
// 运用 sql 创建数据表
$sql = "CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)";
if ($conn->query($sql) === TRUE) { echo "Table MyGuests created successfully";
} else {
echo "创建数据表错误: " . $conn->error;
}
$conn->close();
?>
|