php.net |  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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: maesa at email dot it
New email:
PHP Version: OS:

 

 [2005-09-14 11:44 UTC] maesa at email dot it
Description:
------------
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' );
print_r($dbh->errorInfo());

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

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 

Array
(
    [0] => 00000
)

but for the second call


Array
(
    [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.
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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] sniper@php.net
Assigned to the maintainer
 [2005-09-14 16:58 UTC] wez@php.net
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] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

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

sorry
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Nov 29 02:01:23 2020 UTC