|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-02-20 05:23 UTC] 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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 11:00:02 2025 UTC |
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);Ok, I've removed the mysql_errno() check on fetchInto(). IMHO this is a bug in the mysql extension, which doesn't properly reset the error. This problem doesn't ocurr with postgres or interbase. Test script to reproduce the problem: <?php $con = mysql_connect('localhost', 'root'); mysql_selectdb('test'); $res = mysql_query('SELECT * FROM table'); $continue = true; do { $row = mysql_fetch_row($res); if (mysql_errno()) { // Here there is no fetch_row error, it's the same // from FAKE QUERY echo "Failed fetching with error: " . mysql_errno() . "\n"; // Don't want to continue on fetch errors $continue = false; } elseif (!$row) { $continue = false; } else { $res2 = mysql_query('FAKE QUERY'); echo "Failed to launch FAKE QUERY: " . mysql_errno() . "\n"; // Ok, I got the error but want to continue $continue = true; } } while ($continue); ?> Output: Failed to launch FAKE QUERY: 1064 Failed fetching with error: 1064