It was long a well-known bug in PHP that PDOStatement::debugDumpParams() did not do what the documentation claimed – specifically, it didn’t do the only thing it would have been really useful for, outputting the actual value of bound params or the full, raw query sent to the database. According to the docs, this was fixed in PHP 7.2.0:
PDOStatement::debugDumpParams()
now returns the SQL sent to the database, including the full, raw query (including the replaced placeholders with their bounded values). Note, that this will only be available if emulated prepared statements are turned on.
This recent answer to an old question illustrates this with a screenshot of a debugDumpParams()
call that clearly includes the raw SQL query with params resolved. But for some reason, I cannot that result, whatever I do.
I’m running PHP 8.1 (so > 7.2.0), and I have emulated prepared statements turned on:
print_r($db->getAttribute(PDO::ATTR_EMULATE_PREPARES);
→ outputs “1”
But when I debugDumpParams()
, I always get something like this, frustratingly identical to the pre-7.2.0, buggy behaviour:
SQL: [97] UPDATE table SET field1 = :field1, field2 = :field2 WHERE id = 1234
Params: 2
Key: Name: [9] :field1
paramno=-1
name=[9] ":field1"
is_param=1
param_type=2
Key: Name: [8] :field2
paramno=-1
name=[8] ":field2"
is_param=1
param_type=2
It makes no difference whether I debugDumpParams()
before or after executing the statement.
The server is on shared hosting (One.com Linux server), but I don’t really see how that should be able to make any difference.
What can possibly be going wrong here? What more can I do to get the fixed, intended behaviour of this method?