Error mysqli function for query with 0 record

I use this class for mysql database.

<?php
    class database
    {
        private $db_host="127.0.0.1";
        private $db_user="root";
        private $db_pw="***";
        private $db_db="***";
        private $link;
        private $result;

        public function __construct()
        {
            $this->link=mysqli_connect($this->db_host,$this->db_user,$this->db_pw,$this->db_db) or die("Cant contact db");
        }

        public function __destruct()
        {
            mysqli_close($this->link);
        }

        public function execute($query)
        {
            $this->result=mysqli_query($this->link, $query) or die("Query error");      
        }

        public function nrows()
        {
            return mysqli_affected_rows($this->link) or die("Error nrows");
        }

        public function fetch()
        {
            return mysqli_fetch_row($this->result) or die("Error fetch");
        }
    }

?>

Then

require_once "db.php";
$db=new database();
$db->query($query);
$num=$db->nrows();

This work right except when my query return 0 record.
If my query return 0 record I have “Error nrows”.
Also with mysqli_fetch_rows (fetch function) I have the same problem only if my query return 0 record.
Could someone help me understand why I have this problem?
Thank you guys.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s