我有这个用于数据库交互的课程。它工作正常。
<?php require_once('inc/config.inc.php'); ?>
<?php
final class MySQL {
private $link;
public function __construct($hostname, $username, $password, $database) {
if (!$this->link = mysql_connect($hostname, $username, $password)) {
//error('Error: Could not make a database link using ' . $username . '@' . $hostname);
}
if (!mysql_select_db($database, $this->link)) {
//error('Error: Could not connect to database ' . $database);
}
//echo "open". time();
}
public function __destruct() {
mysql_close(); // Problem In here
//echo "closed". time();
}
}
$database=new MySQL(DB_SERVER,DB_USER,DB_PASS,DB_NAME);
?>
但是如果我替换 mysql_close(); 用 mysql_close($this->link);
我收到一个错误:警告:mysql_close() 期望参数 1 是资源,给定 null