这个代码有问题吗? 为什么老是创建不了数据库表?
<?php
$con = mysql_connect("localhost","root","") or die("连接错误");
$ab = mysql_select_db("my_db", $con);
if($ab){
echo "成功了";
}
$sql = "CREATE TABLE `test` (
`id` int(10) NOT NULL auto_increment,
`uid` varchar(10) NOT NULL default '0',
`regdate` date NOT NULL,
`remark` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk AUTO_INCREMENT=1 ;
INSERT INTO `test` (`id`, `uid`, `regdate`, `remark`) VALUES
(1, '张三', '2008-07-02', '学生'),
(2, '李四', '2008-07-03', '学生'),
(3, '王五', '2008-07-02', '工人'),
(4, '赵六', '2008-07-01', '学生');
";
$abc = mysql_query($sql,$con);
if($abc){
echo "建立成功";
}else {
echo "失败了";
}
?>
------解决方案--------------------
$con = mysql_connect("localhost","root","") or die("连接错误");
$ab = mysql_select_db("my_db", $con);
if($ab){
echo "成功了";
}
$sql = "CREATE TABLE `test` (
`id` int(10) NOT NULL auto_increment,
`uid` varchar(10) NOT NULL default '0',
`regdate` date NOT NULL,
`remark` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk AUTO_INCREMENT=1 ;
$abc = mysql_query($sql,$con);
if($abc){
echo "建立成功";
}else {
echo "失败了";
}
$sql1="INSERT INTO `test` (`id`, `uid`, `regdate`, `remark`) VALUES
(1, '张三', '2008-07-02', '学生')"
$result=mysql_query($sql1);
if($result){
echo "插入数据成功";
}
------解决方案--------------------把$abc的mysql错误信息输出出来看看
PS, 12行少个结束双引号