I am trying to learn the basics of OOP PHP however I am stuck at this part:
<?php
class Database {
private $dbuser;
private $dbpass;
private $dbhost;
private $database;
private $link;
private $connection;
function __construct($dbhost, $dbuser, $dbpass, $database) {
$this->dbhost = $dbhost;
$this->dbuser = $dbuser;
$this->dbpass = $dbpass;
$this->database = $database;
$this->link = mysql_connect($this->dbhost, $this->dbuser, $this->dbpass);
$this->link = mysql_select_db($this->database);
return true;
}
function NewQuery($query) {
$execute = mysql_query($query);
if (!$execute) die('Invalid query: ' . mysql_error());
return $execute;
}
function __destruct() {
mysql_close($this->link);
}
}
At my index page I get this error on mysql_close. Is there anything I could do to fix it on __destruct() class?
Warning: mysql_close() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\projects\oop\classes\database.php on line 33