note 84588 modified in ref.pdo-mysql by danbrown
| From: | danbrown@php.net | Date: | Sun, 20 Jul 2008 21:06:26 +0000 |
| Subject: | note 84588 modified in ref.pdo-mysql by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142338@lists.php.net to get a copy of this message | ||
SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are
active. ...
This one can be a royal pain to deal with. Never stack statements to be executed in one go. Nobody
ever mentions this possibility in all the posts I've seen dealing with this error.
This example is a Zend Framework example but the theory is the same.
As in:
<?php
$sql = <<<____SQL
CREATE TABLE IF NOT EXISTS
ticket_hist (
tid int(11) NOT NULL,
trqform varchar(40) NOT NULL,
trsform varchar(40) NOT NULL,
tgen datetime NOT NULL,
tterm datetime,
tstatus tinyint(1) NOT NULL
) ENGINE=ARCHIVE COMMENT='ticket archive';
CREATE TABLE IF NOT EXISTS request_hist (
rqid int(11) NOT NULL,
rqtid int(11) NOT NULL,
rqsid int(11) NOT NULL,
rqdate datetime NOT NULL,
rqcode tinyint(1) NOT NULL,
rssid int(11) NOT NULL,
rsdate datetime,
rscode tinyint(1)
) ENGINE=ARCHIVE COMMENT='request archive';
CREATE TABLE IF NOT EXISTS relay_hist (
rqid int(5) NOT NULL,
sdesc varchar(40) NOT NULL,
rqemail varchar(40) NOT NULL,
sid int(11) NOT NULL,
rlsid int(11) NOT NULL,
dcode varchar(5) NOT NULL
) ENGINE=ARCHIVE COMMENT='relay archive';
____SQL;
$result = $this->db->getConnection()->exec($sql);
?>
This will run fine but PDO will balk with the 'unbuffered' error if you follow this with
another query.
Instead do:
<?php
$sql = <<<____SQL
CREATE TABLE IF NOT EXISTS ticket_hist (
tid int(11) NOT NULL,
trqform varchar(40) NOT NULL,
trsform varchar(40) NOT NULL,
tgen datetime NOT NULL,
tterm datetime,
tstatus tinyint(1) NOT NULL
) ENGINE=ARCHIVE COMMENT='ticket archive';
____SQL;
$result = $this->db->getConnection()->exec($sql);
$sql = <<<____SQL
CREATE TABLE IF NOT EXISTS request_hist (
rqid int(11) NOT NULL,
rqtid int(11) NOT NULL,
rqsid int(11) NOT NULL,
rqdate datetime NOT NULL,
rqcode tinyint(1) NOT NULL,
rssid int(11) NOT NULL,
rsdate datetime,
rscode tinyint(1)
) ENGINE=ARCHIVE COMMENT='request archive';
____SQL;
$result = $this->db->getConnection()->exec($sql);
$sql = <<<____SQL
CREATE TABLE IF NOT EXISTS relay_hist (
rqid int(5) NOT NULL,
sdesc varchar(40) NOT NULL,
rqemail varchar(40) NOT NULL,
sid int(11) NOT NULL,
rlsid int(11) NOT NULL,
dcode varchar(5) NOT NULL
) ENGINE=ARCHIVE COMMENT='relay archive';
____SQL;
$result = $this->db->getConnection()->exec($sql);
?>
Chopping it into individual queries fixes the problem.
--was--
SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are
active. ...
This one can be a royal pain to deal with. Never stack statements to be executed in one go. Nobody
ever mentions this possibility in all the posts I've seen dealing with this error.
This example is a Zend Framework example but the theory is the same.
As in:
$sql = <<<____SQL
CREATE TABLE IF NOT EXISTS ticket_hist (
tid int(11) NOT NULL,
trqform varchar(40) NOT NULL,
trsform varchar(40) NOT NULL,
tgen datetime NOT NULL,
tterm datetime,
tstatus tinyint(1) NOT NULL
) ENGINE=ARCHIVE COMMENT='ticket archive';
CREATE TABLE IF NOT EXISTS request_hist (
rqid int(11) NOT NULL,
rqtid int(11) NOT NULL,
rqsid int(11) NOT NULL,
rqdate datetime NOT NULL,
rqcode tinyint(1) NOT NULL,
rssid int(11) NOT NULL,
rsdate datetime,
rscode tinyint(1)
) ENGINE=ARCHIVE COMMENT='request archive';
CREATE TABLE IF NOT EXISTS relay_hist (
rqid int(5) NOT NULL,
sdesc varchar(40) NOT NULL,
rqemail varchar(40) NOT NULL,
sid int(11) NOT NULL,
rlsid int(11) NOT NULL,
dcode varchar(5) NOT NULL
) ENGINE=ARCHIVE COMMENT='relay archive';
____SQL;
$result = $this->db->getConnection()->exec($sql);
This will run fine but PDO will balk with the 'unbuffered' error if you follow this with
another query.
Instead do:
$sql = <<<____SQL
CREATE TABLE IF NOT EXISTS ticket_hist (
tid int(11) NOT NULL,
trqform varchar(40) NOT NULL,
trsform varchar(40) NOT NULL,
tgen datetime NOT NULL,
tterm datetime,
tstatus tinyint(1) NOT NULL
) ENGINE=ARCHIVE COMMENT='ticket archive';
____SQL;
$result = $this->db->getConnection()->exec($sql);
$sql = <<<____SQL
CREATE TABLE IF NOT EXISTS request_hist (
rqid int(11) NOT NULL,
rqtid int(11) NOT NULL,
rqsid int(11) NOT NULL,
rqdate datetime NOT NULL,
rqcode tinyint(1) NOT NULL,
rssid int(11) NOT NULL,
rsdate datetime,
rscode tinyint(1)
) ENGINE=ARCHIVE COMMENT='request archive';
____SQL;
$result = $this->db->getConnection()->exec($sql);
$sql = <<<____SQL
CREATE TABLE IF NOT EXISTS relay_hist (
rqid int(5) NOT NULL,
sdesc varchar(40) NOT NULL,
rqemail varchar(40) NOT NULL,
sid int(11) NOT NULL,
rlsid int(11) NOT NULL,
dcode varchar(5) NOT NULL
) ENGINE=ARCHIVE COMMENT='relay archive';
____SQL;
$result = $this->db->getConnection()->exec($sql);
Chopping it into individual queries fixes the problem.
http://php.net/manual/en/ref.pdo-mysql.php