- Code: Select all
Notice: Use of undefined constant DB_SERVER - assumed 'DB_SERVER' in C:\xampp-portable\htdocs\gallery\includes\database.php on line 12
Here is my index.php file located in "gallery/public/" folder
- Code: Select all
<?php
require_once("../includes/database.php");
if (isset($database)){
echo "Is this working?";
}
?>
Here is the config.php located in "gallery/includes/" folder
- Code: Select all
<?php
define('DB_SERVER', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_NAME', 'photo_gallery');
?>
and here is the database.php located in "gallery/includes/" folder
- Code: Select all
<?php
require_once("config.php");
class MySQLDatabase {
private $connection;
function __construct() {
$this->open_connection();
}
public function open_connection() {
$this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
if (!$this->connection) {
die("Database connection failed: " . mysql_error());
} else {
$db_select = mysql_select_db(DB_NAME, $this->connection);
if (!$db_select) {
die("Database selection failed: " . mysql_error());
}
}
}
public function close_connection() {
if(isset($this->connection)) {
mysql_close($this->connection);
unset($this->connection);
}
}
}
$database = new MySQLDatabase();
$db =& $database;
?>