I have this class for DB interactions. It works fine.
<?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);
?>
But if I replace mysql_close(); with mysql_close($this->link);
I get an error: Warning: mysql_close() expects parameter 1 to be resource, null given