I have a Singleton pattern Database object which I would like to declare once for use within the system. I have a main include file which serves up all of the separate class files and also makes some global variables.
Here's the include file:
<?php
// Main API. We want to include everything here and then make some Global Vars:
require_once('database.class.php');
// Create the DB here:
$database = Database::Singleton();
require_once('user.class.php');
require_once('settings.class.php');
// Start the session:
session_start();
?>
In theory, $database
should be a global variable accessible by anything included thereafter (i.e. user.class.php
and settings.class.php
. However, when I try to call a method in the Database
class from the User
class as follows:
$result = $database->FetchObject($queryString);
I get the following error:
Fatal error: Call to a member function NumRows() on a non-object in C:\Program Files (x86)\EasyPHP-5.3.4.0\www\PC Estimating\classes\user.class.php on line 122
Is anyone able to help?