From: mark-phpbugs at vectrex dot org dot uk
Operating system: Linux
PHP version: 5.1.4
PHP Bug Type: PDO related
Bug description: In PDO mysql running multiple queries with one exec,
subsequent query fails
Description:
------------
When running multiple queries with one exec, the queries
succeed (or appear to succeed, with no exception), but a
subsequent query fails with 2013 Lost connection to MySQL server during
query
I'm using MySQL 5.0.20a-Debian_2-log on Debian Linux. Client library
version is
"PDO Driver for MySQL, client library version => 5.0.22"
This is similar to "bogus" bug #37732 which affects mysqli - But in PDO
there is no way to manually "consume" the empty result sets from an exec()
- PDO should really do it automatically.
Reproduce code:
---------------
<?php
error_reporting(E_ALL);
function DbInit()
{
global $db;
$options = array();
$connstr = "mysql:host=localhost;dbname=test";
$db = new PDO($connstr, "root", "", $options);
$db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
// Make sure our connections use utf8.
$db->exec("SET NAMES utf8");
}
function TestBatch()
{
global $db;
$sql = "CREATE TEMPORARY table b (t varchar(20))";
$sql2 = " INSERT INTO b VALUES ('hello')";
/* This works
$db->exec($sql);
$db->exec($sql2);
*/
/* This fails because the subsequent query gives 2013 Lost connection to
MySQL server during query */
$db->exec($sql . ";" . $sql2);
$sth = $db->query("SELECT * FROM b");
var_dump($sth->fetchAll(PDO::FETCH_ASSOC));
}
DbInit();
TestBatch();
?>
Expected result:
----------------
array(1) {
[0]=>
array(1) {
["t"]=>
string(5) "hello"
}
}
Actual result:
--------------
Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[HY000]: General error: 2013 Lost connection to MySQL server
during query' in /home/mark/progs/phptest/pdobatch.php:30
Stack trace:
#0 /home/mark/progs/phptest/pdobatch.php(30): PDO->query('SELECT * FROM
b')
#1 /home/mark/progs/phptest/pdobatch.php(35): TestBatch()
#2 {main}
thrown in /home/mark/progs/phptest/pdobatch.php on line 30
--
Edit bug report at http://bugs.php.net/?id=38001&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=38001&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=38001&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=38001&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=38001&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=38001&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=38001&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=38001&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=38001&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=38001&r=support
Expected behavior: http://bugs.php.net/fix.php?id=38001&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=38001&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=38001&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=38001&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=38001&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=38001&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=38001&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=38001&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=38001&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=38001&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=38001&r=mysqlcfg