config.php
<?
// Database Constants
define("DB_SERVER", "localhost");
define("DB_USER", "gallery");
define("DB_PASS", "phpOTL123");
define("DB_DATABASE", "photo_gallery");
?>
database.php
<?php
require_once('config.php');
class MySQLDatabase
{
private $connection;
public function open_connection() {
$this->connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS,DB_NAME);
if (!$this->connection) {
die("Database connection failed: " . mysqli_error());
}
}
}
$database=new MySQLDatabase();
$database->open_connection();
?>
I am defining DB_SERVER and all the other ones as you can see above, but for some reason I get the following errors :
Warning: Use of undefined constant DB_SERVER - assumed 'DB_SERVER' (this will throw an Error in a future version of PHP) in C:\xampp\htdocs\photo_gallery\includes\database.php on line 6
Warning: Use of undefined constant DB_USER - assumed 'DB_USER' (this will throw an Error in a future version of PHP) in C:\xampp\htdocs\photo_gallery\includes\database.php on line 6
Warning: Use of undefined constant DB_PASS - assumed 'DB_PASS' (this will throw an Error in a future version of PHP) in C:\xampp\htdocs\photo_gallery\includes\database.php on line 6
Warning: Use of undefined constant DB_NAME - assumed 'DB_NAME' (this will throw an Error in a future version of PHP) in C:\xampp\htdocs\photo_gallery\includes\database.php on line 6
Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\photo_gallery\includes\database.php on line 6
Warning: mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\photo_gallery\includes\database.php on line 6 Database connection failed: mysqli_error()