<?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());
}
}
?>
在类中破坏mysqli连接是个坏主意吗?或者应该坚持使用标准的mysqli对象,只关闭这样的连接?
$bedtime = new mysqli(....);
$bedtime->query("INSERT..");
$bedtime->close();
答案 0 :(得分:0)
解构将不起作用,因为如果你做了像
这样的事情$conn = $connection->MySQLi(.......);
即使您unset($connection)
,$conn
仍然有效。
如果那是你的目标,请坚持使用普通物体。