sql 语句在phpmyadmin运行正常,但在PHP无法运行

$sql=<<<EOF
DROP TABLE if exists `install`,`user`,`theme`,`reply`;
create table `install` (
`id` int(11) unsigned NOT NULL auto_increment,
`themenum` int(11) NOT NULL,
`webtitle` text NULL,
`weblogo` text NULL,
`webkeywords` text NULL,
`webdescription` text NULL,
`webtop` text NULL,
`webmenu` text NULL,
`webfooter` text NULL,
`custom1` text NULL,
PRIMARY KEY (`id`),
KEY `id` (`id`)
);
EOF;
$resql=mysql_query($sql);
if($resql){
echo "<div align=center><h1>安装成功!请删除掉安装文件</h1><a href=index.php>查看首页</a></div>";
}
else{
$result=mysql_error();
echo "<div align=center>安装出错!<br>$result</div>";
}

出错信息:
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 'create table `install` ( `id` int(11) unsigned NOT NULL auto_increment, `the' at line 2

mysql_query($sql);是执行一条SQL语句, 而你传入的$sql,里有2条。你可以分开来。

一条 DROP TABLE if exists `install`,`user`,`theme`,`reply`;

然后建表重新弄一条语句。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-04-14
你这是两条sql语句!,要分开执行的,去掉drop那句试试,或者选择分开执行!
相似回答