#38001 [Com]: In PDO mysql running multiple queries with one exec, subsequent query fails

From: Date: Wed, 16 Jul 2008 10:47:20 +0000
Subject: #38001 [Com]: In PDO mysql running multiple queries with one exec, subsequent query fails
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-126816@lists.php.net to get a copy of this message
 ID:               38001
 Comment by:       andrea at bhweb dot it
 Reported By:      mark-phpbugs at vectrex dot org dot uk
 Status:           No Feedback
 Bug Type:         PDO related
 Operating System: Linux
 PHP Version:      5.1.4
 New Comment:

Although nasty, I found a workaround, like the one used in mysqli to 
consume the resultsets:

$stmt=$ppdb->prepare($query);
$stmt->execute();
do { $stmt->fetch(); $stmt->closeCursor(); ++$line; } while($stmt-
>nextRowset());

I found this only works using prepare and execute this way, not if you

directly execute the query with query().

HTH


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

[2006-07-12 01:00:01] php-bugs at lists dot php dot net

No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".

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

[2006-07-04 22:11:48] mark-phpbugs at vetrex dot org dot uk

I've tried this with the latest snapshot, php5.2-200607042030, and the
problem remains.

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

[2006-07-04 19:40:37] iliaa@php.net

Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

Works for me using MySQ 5.0.22

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

[2006-07-04 09:12:06] mark-phpbugs at vectrex dot org dot uk

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 this bug report at http://bugs.php.net/?id=38001&edit=1



Thread (6 messages)

« previous php.bugs (#126816) next »