Why an EXPLAIN statement is generated when doing a simple query?

147 views Asked by At

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

1

There are 1 answers

0
xrmnf On

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 like FOUND_ROWS()).

Setting it to Off should resolve your problem.