I am having a lot of trouble including a file in my project.
A low rundown: I have a directory _includes in my root directory. in this I have a database.php and a config.php. The database.php uses require_once() to include config.php. Now in the root directory i have a login.php which uses require.php to include the database.php.
The problem: on its own the database.php works fine. If i open login.php it doesnot seem to be including the config.php. Although it gives no error regarding config.php. But it doesnot recognise the varibles i defined in hte Config.php
The Code:
Config.php:
Code: Select all
<?php
define(DB_SERVER,"localhost");
define(DB_USER,"asdas");
define(DB_PASS,"asdas");
define(DB_NAME,"rasd");
?>Code: Select all
<?php
require_once("config.php");
class MySQLDB{
private $connection;
//Basic Database Connectivity Methods
function __construct(){
$this->openConnection();
}
public function openConnection(){
$this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
if(!$this->connection){
die("Unable To Connect to dbServer: " . mysql_errno());
}
else{
$db = mysql_select_db(DB_NAME, $this->connection);
if(!$db){
die("Unable To Select Database: " . mysql_error());
}
}
}
public function closeConnection(){
if(isset($this->connnection)){
mysql_close($this->connection);
unset($this->connection);
}
}
//Quering Methods
public function query($sql){
$result = @mysql_query($sql);
$this->confirmQuery();
return $result;
}
private function confirmQuery($r){
if(!$r){
die("Query Failed: " . mysql_error());
}
}
private function mysqlPrep($data){
if(function_exists("mysql_real_escape_string")){
if(get_magic_quotes_gpc()){ $data = stripslashes($data); }
$data = mysql_real_escape_string($data);
}
else{
if(!get_magic_quotes_gpc()){ $data = addslashes($data); }
}
return $data;
}
}
$database = new MySQLDB;
$database->openConnection;
?>in login.php all i am doing is incuding this database.php.
But it always returns an mysql error : Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'DB_SERVER' (11001) in C:\xampp\htdocs\CMS\_includes\database.php on line 12
Unable To Connect to dbServer: 2005
if i open only database.php it works fine.
Please help. Just started with php a while ago!
Thanks