#22328 [Com]: Erroneous behaviour of fetchRow method
| From: | tko at lostway dot org | Date: | Tue, 22 Jun 2004 03:18:54 +0000 |
| Subject: | #22328 [Com]: Erroneous behaviour of fetchRow method | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-61198@lists.php.net to get a copy of this message | ||
ID: 22328
Comment by: tko at lostway dot org
Reported By: miki_fossati at libero dot it
Status: Bogus
Bug Type: MySQL related
Operating System: linux suse 7.2
PHP Version: 4.3.3RC2-dev
Assigned To: georg
New Comment:
"mysql bug #706" is not a bug. It is a specification.
So you should check mysql_errno().
A client user should reset errno somehow (I think of re-connecting db)
if he needs.
Previous Comments:
------------------------------------------------------------------------
[2003-06-24 07:29:23] georg@php.net
It's a bug in libmysql which is already reported (mysql bug #
706)
------------------------------------------------------------------------
[2003-06-23 19:30:59] sniper@php.net
Happens with PHP 4.3.3RC2-dev, Georg? :)
------------------------------------------------------------------------
[2003-06-21 11:40:51] cox@php.net
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
------------------------------------------------------------------------
[2003-05-11 01:19:07] mj@php.net
Actually lsmith's fix seems to be fine. Is there anything speaking
against applying it?
------------------------------------------------------------------------
[2003-04-29 15:14:00] lsmith@php.net
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);
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/22328
--
Edit this bug report at http://bugs.php.net/?id=22328&edit=1