I have a database class with several PDO functions inside (db.inc.php). I'm trying to call this function from another function:
// Query method
public function query($query) {
$this->stmt = $this->dbh->prepare($query);
}
In my global PHP file I have instantiated the database using:
// Instantiate database
$database = new database();
However when trying to call this function from another function inside of a different PHP file (user.inc.php):
function confirmAccount($key,$id) {
// Check key and id against entry in database
$database->query('SELECT * FROM users WHERE id = :id');
}
I get the following error:
Fatal error: Call to a member function query() on a non-object in /home/studevne/public_html/includes/user.inc.php on line 10
All of my PHP files are included in the global PHP file as so:
include_once 'includes/db.inc.php';
include_once 'includes/echo.inc.php';
include_once 'includes/tools.inc.php';
include_once 'includes/user.inc.php';
I'm guessing its something to do with the scope of the database class and its functions howevver I'm a little confused on how to solve this. Any help is greatly appreciated.