ID:               36347
 User updated by:  david at acz dot org
 Reported By:      david at acz dot org
-Status:           Bogus
+Status:           Open
 Bug Type:         PDO related
 Operating System: SuSE Linux 9.3
 PHP Version:      5.1.2
 Assigned To:      george
 New Comment:

See my previous comment.  There is no way to execute "OPTIMIZE TABLE"
with MySQL using PDO.


Previous Comments:
------------------------------------------------------------------------

[2006-02-14 15:13:23] [EMAIL PROTECTED]

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

exec() method is intended only for one time execution of queries that
do not return any records. There is no bug here.

------------------------------------------------------------------------

[2006-02-10 15:18:11] [EMAIL PROTECTED]

Assigned to the maintainer.

------------------------------------------------------------------------

[2006-02-10 02:34:48] david at acz dot org

This bug is similar to #34499.  I can't comment on that, so I'm
commenting here:

"OPTIMIZE TABLE is a query that returns rows.
You should use PDO::query() instead.
I'll see about handling this user error more gracefully."

You actually can't use PDO::query() with OPTIMIZE TABLE:

HY000:2030:This command is not supported in the prepared statement
protocol yet

What is the solution?

------------------------------------------------------------------------

[2006-02-10 01:24:25] david at acz dot org

Description:
------------
[Note: I am actually testing this on PHP 5.1.1.  If this bug was fixed
in PHP 5.1.2, please add a note to the manual page for PDO::exec()].

The manual says:

"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()."

Either the manual needs to be changed, or, ideally, PDO::exec() needs
to be fixed to discard results.

This issue has bit me multiple times.  It's easy to forget that a
certain query (such as MySQL's OPTIMIZE TABLE) will return a result. 
Using PDO::exec() in such cases causes an error later that can be
difficult to track down.

Reproduce code:
---------------
<?
     $db = new PDO("mysql:host=localhost;dbname=test");

     $db->exec("SELECT 1");

     $st = $db->prepare("SELECT NOW()");
     if ($st === false)
     {
         $e = $db->errorInfo();
         echo "$e[0]:$e[1]: $e[2]\n";
     }
?>


Expected result:
----------------
[nothing]

Actual result:
--------------
HY000: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. 


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=36347&edit=1

Reply via email to