error in a PHP sentence - WARNING

0

I receive the following error:

Warning: mysqli::query(): Couldn't fetch mysqli in /database.class.php on line 96

and the line is as follows:

public function query($query)
{
    $this->result = $this->mysqli->query($query); // Esta es la linea   
    return $this->result;
}

Above I have this line that connects to the database:

class ConnectMe
{
    public function __construct($db_server, $db_username, $db_password, $db_name) 
    {
        $this->db_server = $db_server;  
        $this->db_username = $db_username;
        $this->db_password = $db_password;
        $this->db_name = $db_name;

        $this->mysqli = new mysqli($this->db_server, $this->db_username, $this->db_password, $this->db_name);

        if($this->mysqli->connect_error)
        {
            return false;
        }

        $this->mysqli->query("SET NAMES 'utf8'");
        $this->mysqli->query('SET character_set_connection=utf8');
        $this->mysqli->query('SET character_set_client=utf8');
        $this->mysqli->query('SET character_set_results=utf8'); 
    }

Could you see what is wrong with me?

Greetings,

    
asked by Eduardo Manuel Leon Cuya 30.10.2018 в 21:29
source

1 answer

0

try like this:

$query = $this->mysqli->prepare($sql)
if($query->execute()){
   return $consulta->get_result();
}
    
answered by 30.10.2018 в 21:38