<?php $servername = "127.0.0.1" ; $username = "root" ; $password = "123456" ;

// 创建连接 $conn = new mysqli($servername,$username,$password); // 检测连接 if ($conn ->connect_error){ die("连接失败".$conn ->connect_error); } echo "数据库连接成功" ;

//创建数据库 $sql = "create database if not exists classdb"; if($conn ->query($sql)==TRUE){ echo"数据库创建成功"; }else { die("创建失败:".mysqli_error($conn)); }

mysqli_select_db( $conn, 'classdb' ); //创建表 $sql1 = "CREATE TABLE IF NOT EXISTS _tbl( _id INT UNSIGNED AUTO_INCREMENT, _title VARCHAR(100) NOT NULL, _author VARCHAR(40) NOT NULL, PRIMARY KEY ( _id ) )ENGINE=InnoDB DEFAULT CHARSET=utf8;";

$retval = mysqli_query( $conn, $sql1 ); if(! $retval ) { die('数据表创建失败: ' . mysqli_error($conn)); } echo "数据表创建成功\n";

?>