|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47655 PDO MySQL prepare is allways emulated
Submitted: 2009-03-14 07:46 UTC Modified: 2009-03-15 08:13 UTC
From: info at chromosoft dot be Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5.2CVS-2009-03-14 (snap) OS: Ubuntu
Private report: No CVE-ID: None
 [2009-03-14 07:46 UTC] info at chromosoft dot be

The prepare is allways emulated on the mysql DB.
But if you  use mysqli the prepare work correctly.

MySQL : 5.0.51a
PHP : 5.2.4-2ubuntu5.5

Reproduce code:
Code with PDO :

$dbh = new PDO('mysql:host=localhost;dbname=db', 'root' , '');
$sth = $dbh->prepare('select * from tt where a = ?');

Code with Mysqli :

$mysqli = new mysqli("localhost", "root", "", "db");
$a = 5;
if ($stmt = $mysqli->prepare("select * from tt where a = ?"))
  $stmt->bind_param("i", $a); 

Actual result:
Log with PDO
30 Connect     root@localhost on db
30 Query       select * from tt where a = '1'
30 Quit 

Log with Mysqli
31 Connect     root@localhost on db
31 Prepare     [1] select * from tt where a = ?
31 Execute     [1] select * from tt where a = 5
31 Quit       


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-14 13:57 UTC]
This was intended due to the mysql api not being quite ready when PDO was written. I believe you can use
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

But there might be bugs with this.
 [2009-03-15 06:41 UTC] info at chromosoft dot be
Great, it works. But there is not much documentation on this option. And I never thought that by default it is FALSE by default/

 [2009-03-15 08:13 UTC] info at chromosoft dot be
It's correct, now I have another problem with prepare. The system say  
"FATAL ERROR : SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute."

And this on a execute function (not on query or fetch) and not on the first execute on this statement, and the MYSQL_ATTR_USE_BUFFERED_QUERY attribute is turn ON. 

If I turn ON the ATTR_EMULATE_PREPARES the program work correctly but without a real prepare.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue May 30 12:03:39 2023 UTC