//代码添加数据库
<?php
header("content-type:text/html;charset=utf-8");
// $servername = "localhost";
// $username = "root";
// $password = "root";
// // 创建连接
// $conn = new mysqli($servername, $username, $password);
// // 检测连接
// if ($conn->connect_error) {
// die("连接失败: " . $conn->connect_error);
// }else{
// echo “连接失败!!!”;
// }
// 创建数据库
$sql = "CREATE DATABASE myDB";
if ($conn->query($sql) === TRUE) {
echo "数据库创建成功";
} else {
echo "Error creating database: " . $conn->error;
}
$conn->close();
//基础 php代码添加表
//建表的sql 语句
$con=mysql_connect("localhost","root","root");
if($con)
{
mysql_select_db("zk2",$con);
mysql_query("set name gtf8");
$sql="create table user_date
(
id int(5) not null auto_increment primary key,
name char(10) not null default '',
password char(12) not null default '',
age int(3) not null default 0,
sex char(10) not null default 'man',
mail char(50) not null default '',
qq char(10) not null default '',
gedree char(10) not null default '',
fav char(50) not null default ''
)";
$do=mysql_query($sql,$con);
if($do)
{
echo "成功!!";
}
else
echo "create error!!!!!";
}
else
{
echo "connect error!!!!";
}