Re: MYSQL Testing [ NumRows ] bug on zero rows returned
| From: | Stig S. Bakken | Date: | Wed, 13 Dec 2000 00:56:18 +0000 |
| Subject: | Re: MYSQL Testing [ NumRows ] bug on zero rows returned | ||
| References: | 1 | Groups: | php.pear |
| Request: | Send a blank email to php-pear+get-672@lists.php.net to get a copy of this message | ||
Ricardo Sada wrote:
>
> Hello !!
>
> I've found a problem with the recently implemented
> numRows for MySql. It returns a DB_error object when no rows are returned
> in a SELECT statement (zero rows), a perfectly valid case.
>
> I came up with a quick fix by changing
> the error checking condition using the mysql_errno function instead
>
> function numRows($result)
> {
> $rows = mysql_num_rows($result);
>
> // if(!rows) returns an error on zero rows
> // instead I use
> if (mysql_errno($this->connection)) {
> return
> $this->raiseError($this->errorCode(
> mysql_errno($this->connection)));
> }
>
> return $rows;
> }
>
> Please let me know if anyones sees a proble with this fix.
An approach that works with more databases is to use the === operator
like this:
function numRows($result)
{
$rows = @mysql_num_rows($result);
if ($rows === null) {
return $this->mysqlRaiseError();
}
return $rows;
}
I'm applying this fix to mysql and pgsql. Thanks!
- Stig