php.net |  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: 2012-05-21 15:26 UTC
Votes:12
Avg. Score:3.8 ± 1.2
Reproduced:7 of 7 (100.0%)
Same Version:3 (42.9%)
Same OS:5 (71.4%)
From: me at ircmaxell dot com Assigned:
Status: Open Package: PDO related
PHP Version: 5.4 OS: All
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2011-04-30 02:25 UTC] me at ircmaxell dot com
Description:
------------
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 
statements.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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 
http://dev.mysql.com/doc/refman/5.1/en/query-cache-operation.html). I think it's 
too early to make the switch.
 [2011-04-30 20:38 UTC] rasmus@php.net
-PHP Version: 5.3SVN-2011-04-30 (SVN) +PHP Version: 5.4
 [2011-04-30 20:38 UTC] rasmus@php.net
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] jpauli@php.net
I agree we should at least document that behavior.
#61969 is related.
 [2012-06-15 01:00 UTC] ircmaxell@php.net
I've added a pull request for this issue:

https://github.com/php/php-src/pull/108
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 16 10:02:09 2014 UTC