[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-pear
Subject:    Re: [PHP-PEAR] MYSQL Testing [ NumRows ] bug on zero rows returned
From:       "Stig S. Bakken" <ssb () fast ! no>
Date:       2000-12-13 0:56:18
[Download RAW message or body]

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

-- 
PHP Extension and Add-on Repository (PEAR) mailing list.
Documentation can be found at http://pear.php.net/doc/pear.html
To unsubscribe, e-mail: php-pear-unsubscribe@lists.php.net from the
mail address you subscribed with.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic