MySQLi是否需要关闭destruct函数?

时间:2017-07-21 11:05:23

标签: php mysql mysqli

我正在创建一个mysqli db对象,执行以下操作:

class DatabaseQK {
public $db;
public function __construct() {
    $this->db = new mysqli(DATABASE_HOST, DATABASE_USER, DATABASE_PASS, DATABASE_NAME, true);

    // if the connection could not be obtained record an error
    if (mysqli_connect_errno()){
        log_system_error("Fatal DB Error: ", mysqli_connect_error());
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }
}

在destruct函数中,以下内容足以关闭连接:

public function __destruct() {}

还是需要这个?

public function __destruct() {
    $this->db->close();
}

0 个答案:

没有答案