PHP MySQL 多语句适用于我的网页,但不适用于 XAMPP
因此,我使用此代码连接到 MySQL 并执行多个语句:
$connect=@mysql_connect($host,$user,$pass,false,65536) or die("Can't connect");
mysql_select_db($base,$connect);
连接后,我执行以下操作:
mysql_query("CREATE TABLE IF NOT EXISTS tablename ...;\nINSERT INTO tablename ...;");
我使用此代码来执行包含上述相同代码的备份文件(\n=换行)。当我在网页(托管服务器)上运行此脚本时,它可以工作,但在我使用 XAMPP 的本地计算机上,它显示错误:
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 'INSERT INTO tablename' at line 2
我已检查 php.ini 并且我有 safe_mode = Off
和 sql.safe_mode = Off
也是如此。
我有什么想法吗?
So I use this code to connect to MySQL and execute multiple statements:
$connect=@mysql_connect($host,$user,$pass,false,65536) or die("Can't connect");
mysql_select_db($base,$connect);
When connected I do:
mysql_query("CREATE TABLE IF NOT EXISTS tablename ...;\nINSERT INTO tablename ...;");
I use this code to execute backup files containing the same code above (\n=new line). When I run this script on my webpage (hosted server) it works but on my local computer where I use XAMPP it shows an error :
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 'INSERT INTO tablename' at line 2
I have checked php.ini and I have safe_mode = Off
and sql.safe_mode = Off
too.
Any ideas what am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据PHP手册,
mysql_query
不支持多个查询。然而,在评论中有一个人说这是可能的:另一方面,手册仅提到该函数有两个参数,所以我想知道如果第五个参数确实有效的话,我们应该将什么作为第三个和第四个参数传递!
According to the PHP manual,
mysql_query
does not support multiple queries. However, in the comments there's a guy stating that it it possible:On the other hand, manual only mentions two parameters to the function, so I wonder what we are supposed to pass as the 3rd and 4th parameters if that 5th one really does the trick!