用php创建数据库,实则是执行MySQL语句


 header("Content-type: text/html; charset=utf-8");
 $servers="localhost";
 $server_name="root";
 $server_pass="root";
 $server_data="name";
 
 $con=mysqli_connect("$servers","$server_name","$server_pass");
 
 $base="CREATE DATABASE $server_data DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci";
 
 if(mysqli_query($con,$base)){
    echo "创建数据库".$server_data."成功!";
 }
 else{
    echo "创建数据库失败!";
 }
 
 mysqli_select_db($con,$server_data);
 $table="CREATE TABLE member (
 id int not null auto_increment,
 PRIMARY KEY(id),
 use_name varchar(20),
 sex varchar(20),
 major varchar(20),
 emaile varchar(20),
 phone varchar(20),
 interview_direction varchar(20),
 learning_style varchar(20),
 add_time int(11)
 )";
 
 if(mysqli_query($con,$table))
 { echo "数据库表创建成功!"; }
 else
 { echo "发生了意外!"; }

 mysqli_close($con);
 
 ?>

你可能感兴趣的:(用php创建数据库,实则是执行MySQL语句)