|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #34054 pdo_mysql driver prepares all queries
Submitted: 2005-08-09 19:37 UTC Modified: 2011-01-06 16:36 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: jonathan+php at daikini dot com Assigned: mysql (profile)
Status: Not a bug Package: PDO related
PHP Version: 5.1.0b3 OS: Mac OS X 10.4.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: jonathan+php at daikini dot com
New email:
PHP Version: OS:


 [2005-08-09 19:37 UTC] jonathan+php at daikini dot com
Using MySQL 4.1.11

The pdo_mysql driver appears to attempt to prepare every query 
that it processes. Unfortunately only certain query statement 
types can be prepared in the current version of MySQL. See:

This is causing a failure in the example code posted.

Perhaps the pdo_mysql driver could look at the type of 
statement it is processing and act accordingly and only 
prepare statements that allow it or perhaps a new option or 
method could be added so that it could be explicitly stated 
that the query should not be prepared.

Reproduce code:
$db = new PDO("mysql:dbname=test;host=", 'root', '');

$db->query('DROP TABLE IF EXISTS pdo_test');
$db->query('CREATE TABLE pdo_test (field1 int(11) default NULL, field2 varchar(20) default NULL)');

$query_that_should_not_fail = "SHOW CREATE TABLE pdo_test";

$result = $db->query($query_that_should_not_fail);
if (!$result) {
   $errorInfo = $db->errorInfo();

$row = $result->fetch(PDO_FETCH_ASSOC);
echo count($row);

Expected result:

Actual result:
    [0] => HY000
    [1] => 1295
    [2] => This command is not supported in the prepared 
statement protocol yet


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-09 19:45 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Use exec() specifically designed for these cases.
 [2005-08-09 19:52 UTC] jonathan+php at daikini dot com
PDO::exec() prepares and executes an SQL statement in a single 
function call, returning the number of rows affected by the 

I don't need to know the number of rows affected by the 
statement. I need a PDOStatement object that I can call fetch 
 [2011-01-01 23:41 UTC]
-Package: Feature/Change Request +Package: MySQL related
 [2011-01-06 16:36 UTC]
-Status: Open +Status: Bogus -Package: MySQL related +Package: PDO related -Assigned To: +Assigned To: mysql
 [2011-01-06 16:36 UTC]
Today's MySQL PDO driver has a fallback to non-prepared execution.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 21 02:01:35 2024 UTC