How do I put $db in a central location, but maintain variable scope
You can't find the correct answer until your code is just a bunch simple PHP scripts. The ultimate solution would be is to use a dependency injection container and resolver where sou can say for example a PDO instance to keep in use until the request ends (in PHP this would be a singleton behavior).

If you can't rewrite your whole system to have an object oriented design to have the ability to use a DI container then the only thing you could do is to create a class loader in your bootstrap section to load a factory.

A Factory is a simple class which can build object instances like a DatabaseFactory::CreateNewConnection would return a new PDO instance. You can create a static factory but that would be as flexible as the pig-iron. A recommend you to have a static DatabaseBuilder class there you can register a DatabaseFactory class instance as the default database factory and your factory can hold a database class instance until the request ends. Here is the skeleton:

&lt;?php

class DatabaseFactoryBuilder {

    private function __construct() {}

    public static function SetFactory(IDatabaseFactory $factory) {
        $this-&gt;_factory = $factory;
    }

    public static function GetFactory() {
        return $this-&gt;_factory;
    }

}

interface IDatabaseFactory {
    function GetDatabase();
}

class DatabaseFactory implements IDatabaseFactory {

    /* ... */

    private $_db;

    public function __construct($dbServer, $dbName, $dbUser, $dbPassword) {
        /* ... */
    }

    public function GetDatabase() {
        if ($this-&gt;_db == NULL) {
            $this-&gt;_db = new PDO(/* ... */);
        }

        return $this-&gt;_db;
    }

}


Ofcourse as you can se you have to create a decent way to set the connection properties for your database.