#22328 [Asn->Ana]: Erroneous behaviour of fetchRow method

From: Date: Tue, 29 Apr 2003 20:14:01 +0000
Subject: #22328 [Asn->Ana]: Erroneous behaviour of fetchRow method
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-15732@lists.php.net to get a copy of this message
ID: 22328 Updated by: lsmith@php.net Reported By: miki_fossati at libero dot it -Status: Assigned +Status: Analyzed Bug Type: PEAR related Operating System: linux suse 7.2 PHP Version: 4.3.0 Assigned To: lsmith New Comment: the problem is in the implementation of fetchInto: function fetchInto($result, &$arr, $fetchmode, $rownum=null) { if ($rownum !== null) { if (!@mysql_data_seek($result, $rownum)) { return null; } } if ($fetchmode & DB_FETCHMODE_ASSOC) { $arr = @mysql_fetch_array($result, MYSQL_ASSOC); } else { $arr = @mysql_fetch_row($result); } if (!$arr) { $errno = @mysql_errno($this->connection); if (!$errno) { return NULL; } return $this->mysqlRaiseError($errno); } return DB_OK; } this line picks up the error that was meant for the "FAKE QUERY" and think by mistake that therefore not the end of the result set was reached but an error occured. Since during a fetch only a connection error can occur it might be a good idea to remove the mysql_errno() call in order to fix this. Alternative we could check for a connection error: if (!$arr) { $errno = @mysql_errno($this->connection); if ($errno == 2013) { return $this->mysqlRaiseError($errno); } return NULL; } $errno = @mysql_errno($this->connection); Previous Comments: ------------------------------------------------------------------------ [2003-04-28 03:58:57] arnaud@php.net changing status ------------------------------------------------------------------------ [2003-02-20 05:23:10] miki_fossati at libero dot it In the following code: --- starts here --- require_once 'DB.php'; $connString = "mysql://user:pass@localhost/my_db"; $mysqlDb = DB::connect("$connString", true); $result = $mysqlDb->query("SELECT id FROM table WHERE name='foo' LIMIT 0, 3"); if (!DB::isError($result)) { while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) { extract($row); echo "$id <br />"; $result2=$mysqlDb->query("FAKE QUERY"); if(!DB::isError($result2)) { //Never here } else { //Continue loop } } } --- ends here --- the loop continues forever. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=22328&edit=1

« previous php.pear.dev (#15732) next »