-1

I have a problem with my code and I don't understand where is, So my code is :

public function getCurrentCycle()
{
    $cycle = NULL;       
    $sql="SELECT * FROM " . Test::TABLE_NAME . " WHERE NOW() BETWEEN begin_date AND finish_date LIMIT 1";             
    $res = PzfMysql :: query($sql, $this->dbconnection);    
    if(mysql_num_rows($res) == 1)
    {
        $cycle = PzfMysql::fetch_object($res, 'Test');
    }  
    return $cycle;
}

I verified $this->dbconnection is set = name of connection,$res it's retourn Resource id #11 but I get an error:

ERROR : 2, mysql_num_rows() expects parameter 1 to be resource, null 

Help me please, Thx in advance

hakre
  • 184,866
  • 48
  • 414
  • 792
TanGio
  • 766
  • 2
  • 12
  • 32

1 Answers1

0

Use this for the if statement:

if($res && mysql_num_rows($res) == 1)

You should avoid using a helper database class and at the same time call mysql functions directly: PzfMysql::mysql_num_rows() instead of mysql_num_rows().

Also, mysql_num_rows() is deprecated (http://php.net/manual/en/function.mysql-num-rows.php). Consider using MySQLi or PDO_MySQL.

vim
  • 1,525
  • 12
  • 16