|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #54638 PDO_MYSQL Always Uses Emulated Prepared Statements
Submitted: 2011-04-30 02:25 UTC Modified: 2017-07-24 22:05 UTC
Avg. Score:3.7 ± 1.3
Reproduced:8 of 8 (100.0%)
Same Version:4 (50.0%)
Same OS:6 (75.0%)
From: me at ircmaxell dot com Assigned:
Status: Suspended Package: PDO related
PHP Version: 5.4 OS: All
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: me at ircmaxell dot com
New email:
PHP Version: OS:


 [2011-04-30 02:25 UTC] me at ircmaxell dot com
The PDO_MySQL driver defaults emulate_prepare to 1, which forces all prepared 
queries to be emulated by the driver.  This means that even though the client 
library (mysqlnd or libmysql) may support prepared statements, PDO will never 
really use them.

You can set the attribute PDO::ATTR_EMULATE_PREPARES to 0, and it prepares and 
executes the prepared statements just fine using the native mode (rather than 
emulation).  However this is not documented at all on PHP.NET.

Since PDO_MYSQL will fallback to emulation automatically if the client library or 
server are too old for prepared statements, I would suggest that the default 
value for emulate_prepare should be set to 0 to allow for true prepared 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-30 17:38 UTC] damien at tournoud dot net
Before MySQL 5.1.17, prepared statements completely skip the query cache (see I think it's 
too early to make the switch.
 [2011-04-30 20:38 UTC]
-PHP Version: 5.3SVN-2011-04-30 (SVN) +PHP Version: 5.4
 [2011-04-30 20:38 UTC]
This is a 5.4 feature request. There were very good reasons for not using the 
native prepared statement support in MySQL < 5.1.17.
 [2012-05-21 15:26 UTC]
I agree we should at least document that behavior.
#61969 is related.
 [2012-06-15 01:00 UTC]
I've added a pull request for this issue:
 [2017-07-24 22:05 UTC]
-Status: Open +Status: Suspended
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon Jan 24 21:03:34 2022 UTC