为什么在进行简单查询时会生成 EXPLAIN 语句?
我正在使用 MDB2 查询 MySQL 数据库,但是当我查询数据库时,MySQL 记录跟踪 2 条语句:第一个是解释语句,第二个是我的查询。
这是代码:
$sql = "SELECT 1 FROM DUAL";
$mdb2Instance = new MDB2();
$options = array(
'portability' => MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_FIX_CASE,
);
$connection = $mdb2Instance->singleton($dsn, null);
$connection->setFetchMode(MDB2_FETCHMODE_ASSOC);
$connection->query($sql);
我在 MySQL 中收到以下日志:
5 Init DB cma
5 Query EXPLAIN SELECT 1 FROM DUAL
5 Query SELECT 1 FROM DUAL
5 Quit
有人能解释一下发生了什么以及如何防止这种情况吗?
问候
阿尔班
I am using MDB2 to make query to my MySQL database but when I query the database, the MySQL log trace 2 statements: the first one is an explain statement and the second is my query.
Here is the code:
$sql = "SELECT 1 FROM DUAL";
$mdb2Instance = new MDB2();
$options = array(
'portability' => MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_FIX_CASE,
);
$connection = $mdb2Instance->singleton($dsn, null);
$connection->setFetchMode(MDB2_FETCHMODE_ASSOC);
$connection->query($sql);
And I get the following log in MySQL:
5 Init DB cma
5 Query EXPLAIN SELECT 1 FROM DUAL
5 Query SELECT 1 FROM DUAL
5 Quit
Can someone explain me what's happening and how to prevent this?
Regards
Alban
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是由 PHP 配置指令
>mysql.trace-mode
引起的,将此设置设置为 On 时,每个查询之前都会有
EXPLAIN
查询。 PHP 手册并没有说这种行为会发生,但遗憾的是它可能会严重破坏事情(很多应用程序依赖于像FOUND_ROWS()
这样的查询)。将其设置为“关闭”应该可以解决您的问题。
This is caused by PHP configuration directive
>mysql.trace-mode
With this setting set to On, every query is preceded by
EXPLAIN
query. The PHP manual doesn't say that this behaviour occurs and it's a shame for it can break things badly (a lot of apps counting on queries likeFOUND_ROWS()
).Setting it to Off should resolve your problem.