PHP MySQL 多语句适用于我的网页,但不适用于 XAMPP [英] PHP MySQL Multi-statement works on my webpage but not on XAMPP

查看:48
本文介绍了PHP MySQL 多语句适用于我的网页,但不适用于 XAMPP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我用这段代码连接MySQL并执行多条语句:

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);

连接时:

mysql_query("CREATE TABLE IF NOT EXISTS tablename ...;\nINSERT INTO tablename ...;");

我使用此代码来执行包含上述相同代码的备份文件(\n=换行).当我在我的网页(托管服务器)上运行此脚本时,它可以工作,但在我使用 XAMPP 的本地计算机上,它显示错误:

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

我已经检查了 php.ini,我也有 safe_mode = Offsql.safe_mode = Off.

I have checked php.ini and I have safe_mode = Off and sql.safe_mode = Off too.

知道我错过了什么吗?

推荐答案

根据 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:

但是,似乎支持多个查询.您只需将标志 65536 作为 mysql_connect 的 5 参数(client_flags)传递.(来源)

However, multiple queries seem to be supported. You just have to pass flag 65536 as mysql_connect's 5 parameter (client_flags). (Source)

另一方面,手册只提到了函数的两个参数,所以我想知道如果第 5 个参数真的起作用,我们应该将什么作为第 3 个和第 4 个参数传递!

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!

这篇关于PHP MySQL 多语句适用于我的网页,但不适用于 XAMPP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆