note 65378 modified in function.pdostatement-closecursor by danbrown

From: Date: Fri, 28 Nov 2008 22:03:34 +0000
Subject: note 65378 modified in function.pdostatement-closecursor by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-147297@lists.php.net to get a copy of this message
When running multiple queries one after another especially when stored procedures are involved one must release all result sets and fetch all rows in each result set for a stored procedure before moving onto the next query. This is important because a stored procedure returns an extra (empty) result set as a result of having called the procedure itself. In my case calling PDOStatement :: closeCursor() did not work (on php-5.1.3-rc2) and I was presented with the following error message: "SQLSTATE[HY000]: General error: 2013 Lost connection to MySQL server during query" upon trying to PDO :: prepare() my second query. So I used the following drop in replacement within one of my classes which fixed the issue. <?php /** * @param PDOStatement $oStm */ public static function closeCursor($oStm) { do $oStm->fetchAll(); while ($oStm->nextRowSet()); } ?> --was-- When running multiple queries one after another especially when stored procedures are involved one must release all result sets and fetch all rows in each result set for a stored procedure before moving onto the next query. This is important because a stored procedure returns an extra (empty) result set as a result of having called the procedure itself. In my case calling PDOStatement :: closeCursor() did not work (on php-5.1.3-rc2) and I was presented with the following error message: "SQLSTATE[HY000]: General error: 2013 Lost connection to MySQL server during query" upon trying to PDO :: prepare() my second query. So I used the following drop in replacement within one of my classes which fixed the issue. <?php /** * @param PDOStatement $oStm */ public static function closeCursor($oStm) { do $oStm->fetchAll(); while ($oStm->nextRowSet()); } ?> http://php.net/manual/en/function.pdostatement-closecursor.php

« previous php.notes (#147297) next »