从另一个函数调用公共函数

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.

You need to pass $database into the function, else it's out of scope. You can either pass it in as a parameter:

function confirmAccount($key,$id,$database) {
    // Check key and id against entry in database
    $database->query('SELECT * FROM users WHERE id = :id');
}

Or as a global:

function confirmAccount($key,$id) {
    global $database;
    // Check key and id against entry in database
    $database->query('SELECT * FROM users WHERE id = :id');
}

globals are generally frowned upon, as they make it very easy to write messy code.