MongoClient::selectDB PHP Method

selectDB() public method

Gets a database
public selectDB ( string $name ) : MongoDB
$name string - The database name.
return MongoDB - Returns a new database object.
    public function selectDB($name)
    {
        if (!isset($this->databases[$name])) {
            $this->databases[$name] = new MongoDB($this, $name);
        }
        return $this->databases[$name];
    }

Usage Example

示例#1
0
function getConnection($cache = false)
{
    static $first;
    $conf = new \ActiveMongo2\Configuration(__DIR__ . "/tmp/mapper.php");
    $conf->addModelPath(__DIR__ . '/docs')->development();
    if (!empty($_SERVER["NAMESPACE"])) {
        if (!$first) {
            print "Using namespace {$_SERVER['NAMESPACE']}\n";
        }
        $conf->SetNamespace($_SERVER["NAMESPACE"]);
    }
    if (!$first) {
        $mongo = new MongoClient();
        $mongo->selectDB('activemongo2_tests')->drop();
        $mongo->selectDB('activemongo2_tests_foobar')->drop();
        $config = new ActiveMongo2\Configuration();
        unlink($config->getLoader());
    }
    if (empty($_SERVER["NAMESPACE"])) {
        $zconn = new \ActiveMongo2\Client(new MongoClient(), 'activemongo2_tests', __DIR__ . '/docs');
    } else {
        $zconn = new \ActiveMongo2\Connection($conf, new MongoClient(), 'activemongo2_tests');
    }
    $zconn->AddConnection('foobar', new MongoClient(), 'activemongo2_tests_foobar', 'zzzz');
    if ($cache) {
        $zconn->setCacheStorage(new \ActiveMongo2\Cache\Storage\Memory());
    }
    $first = true;
    return $zconn;
}
All Usage Examples Of MongoClient::selectDB