I have been trying to spot the problem in the
<?php
require_once("config.php");
class MYSQLDatabase{
private $connection;
// open the connection as soon as object is created
function __construct(){
$this->open_connection();
}
public function open_connection(){
$this->connection = mysql_connect("DB_SERVER", "DB_USER", "DB_PASS");
if(!$this->connection){
die("Database failed " . mysql_error());
}else{
$db_select = mysql_select_db(DB_NAME, $this->connection);
if(!$db_select){
die("Database connection failed " . mysql_error());
}
}
}
public function close_connection(){
if(isset($this->connection)){
mysql_close($this->connection);
unset($this->connection);
}
}
public function query($sql){
$result = mysql_query($sql, $this->connection);
$this->confirm_query($result);
return $result;
}
private function confirm_query($result){
if(!result){
die("Database query failed: " . mysql_error());
}
}
}
$database = new MYSQLDatabase();
?>
When I go to the index.php file and test the class with the code below i get the following error:
This page isn’t working
localhost is currently unable to handle this request. HTTP ERROR 500.
require_once("../includes/database.php");
if(isset($database)){
echo "true";
}else{
echo "false";
}