|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34499 pdo::exec fails when executing sequential 'OPTIMIZE TABLE' queries
Submitted: 2005-09-14 11:44 UTC Modified: 2005-09-14 18:54 UTC
From: maesa at email dot it Assigned: wez (profile)
Status: Not a bug Package: PDO related
PHP Version: 5.1.0RC1 OS: Windows XP SP2
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: maesa at email dot it
New email:
PHP Version: OS:


 [2005-09-14 11:44 UTC] maesa at email dot it
A pdo::exec call fails when i try to execute sequential query ( 'OPTIMIZE TABLE' queries )

Reproduce code:
$dsn = 'mysql:dbname=my_database;host=localhost';
$user = 'root';
$password = '';

try {
   $dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
   echo 'Connection failed: ' . $e->getMessage();

$dbh->exec( 'OPTIMIZE TABLE my_table' );

$dbh->exec( 'OPTIMIZE TABLE my_table_1' );

Expected result:
I expected that the second call to $dbh->exec will be successful as the first one, but the second fails.

Actual result:
Printing the array returned from $dbh->errorInfo() i obtain for the first call to pdo::exec 

    [0] => 00000

but for the second call

    [0] => HY000
    [1] => 2014
    [2] => 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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-14 13:25 UTC] maesa at email dot it
I've installed the snapshot package for windows and got it running but the problem persist...
 [2005-09-14 13:47 UTC]
Assigned to the maintainer
 [2005-09-14 16:58 UTC]
OPTIMIZE TABLE is a query that returns rows.
You should use PDO::query() instead.
I'll see about handling this user error more gracefully.
 [2005-09-14 18:50 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

Error reporting issue was addressed, but for optimize query you really should be using the query() and not the exec() method.
 [2005-09-14 18:54 UTC] maesa at email dot it
I'm sorry, in the documentation for the exec function i've only read this about returning results

'PDO::exec() does not return results from a SELECT statement. For a SELECT statement that you only need to issue once during your program, consider issuing PDO::query(). For a statement that you need to issue multiple times, prepare a PDOStatement object with PDO::prepare() and issue the statement with PDOStatement::execute().'

and so i thought that for other queries different from SELECT the pdo::exec should have to work

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 00:01:33 2024 UTC