Selecting a MongoDB database in PHP

After connecting to the database server, you can obtain a handle to the database using the following syntax.

$db = $connection->selectDB('databasename');

A shorthand way to selecting a database is as follows:

$db = $connection->databasename;

If there is no database with the specified name, MongoDB will automatically create it.

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.