<?php
class connection
{
public $host, $username, $password, $database;
function __construct($host, $username, $password, $database)
{
$this->host = $host;
$this->username = $username;
$this->password = $password;
$this->database = $database;
}
function MySQLi()
{
return new mysqli($this->host, $this->username, $this->password, $this->database);
}
public function __destruct()
{
mysqli_close($this->MySQLi());
}
}
?>
Is destructing mysqli connections inside of a class a bad idea? Or should one stick to standard mysqli objects and just close connections like this?
$bedtime = new mysqli(....);
$bedtime->query("INSERT..");
$bedtime->close();
The deconstruction won’t work, because if you do something like
even if you
unset($connection),$connwill remain active.Stick with normal objects if that’s your target.