I'm just trying to run a website on my local which I copied from server.
In my config.php
:
define ( 'DB_SERVER', '127.0.0.1' );
define ( 'DB_USERNAME', 'user' );
define ( 'DB_PASSWORD', 'password' );
define ( 'DB_DATABASE', 'database' );
class DB_Class {
function __construct() {
$connection = mysql_connect ( DB_SERVER, DB_USERNAME, DB_PASSWORD ) or die ( 'Connection error -> ' . mysql_error () );
mysql_select_db ( DB_DATABASE, $connection ) or die ( 'Database error -> ' . mysql_error () );
}
}
In my user.php
:
include_once 'config.php';
class User {
// Database connect
public function __construct() {
$db = new DB_Class ();
}
}
In my index.php
:
session_start ();
include_once ('classes/user.php');
$uobj = new User ();
Now whenever I attempt to create an object of a class User
it returns a Fatal error: Class 'DB_Class' not found
on the line where I attempt, in this case it's line 6. Though it works perfectly fine on server.
I tried to extend the class User
to the class DB_Class
but then again the same error on the line where I attempt to extend.
Someone please point out what's wrong. Thanks.