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: 2017-07-24 22:05 UTC
Votes:16
Avg. Score:3.6 ± 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
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
 [2017-07-24 22:05 UTC] kalle@php.net
-Status: Open +Status: Suspended
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 21:01:30 2024 UTC