Please wait while we load your page...
 

Announcements

PHP Manual :: Getting a Database



Making a Connection || Getting A Collection || Tutorial || PHP Manual

To select a database, use:

<?php
$connection 
= new MongoClient();
$db $connection->dbname;
?>

The database does not need to be created in advance, you can create new databases by selecting them.

Be careful of typos! You can inadvertently create a new database, which can cause confusing errors (here name is misspelled as anme in the second selection:

<?php
$connection 
= new MongoClient();

$db $connection->mybiglongdbname;
// do some stuff

$db $connection->mybiglongdbanme;
// now connected to a different database!
?>

The API documentation on the MongoDB class contains more information about database objects.



Making a Connection || Getting A Collection || Tutorial || PHP Manual
Live Chat Not Available