大神帮我看看我的数据库为什么连接成功,选择数据库也成功,但老是创建不了数据表呢??代码如下

<head><meta charset="utf-8"></head>
<?php
//向mysql数据库中发送一条创建数据表的sql语句

//连接数据库
$link = mysql_connect('localhost','root','[email protected]');

//判断连接数据库是否成功
if ($link){
echo '连接数据库成功';
}else{
die ('连接数据库失败!错误号为:' . mysql_errno() . '失败原因:' . mysql_error());
}
$db = mysql_select_db('test');
if ($db) {
echo '选择数据库失败';
}else{
die ('选择数据库失败!错误号为:' . mysql_errno() . '失败原因:' . mysql_error());
}

//拼装创建表的sql语句
$sql = "create table students(";
$sql = "stuId int(4) not null auto_increment primary key,";
$sql = "stuName varchar(200) not null,";
$sql = "stuSex tinyint not null default 1,";
$sql = 'stuBirth date not null,';
$sql = "classId int(4) not null);";
//执行创建表语句
if (mysql_query($sql)){
echo '创建表成功';
}else{
echo '创建表失败';
}

//关闭数据库连接
mysql_close($link);

?>

第1个回答  2014-08-13
看看错误信息是什么,会不会是表已经存在?追问

表是不存在的,而且刚刚我die输出了一下,他显示You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'classId int(4) not null)' at line 1

追答

那把 

$sql = "classId int(4) not null);";


中的引号中的那个分号 ;  去掉试试:

$sql = "classId int(4) not null)";

追问

谢谢大亲啊,那个封号是mysql结束标识符,去掉不行的,没有去掉,是因为我选择数据库失败了变量中缺少感叹号,,现在成功了,谢谢你哦

本回答被提问者采纳