To select a database, use:
<span style="font-size:14px;"><?php $connection = new MongoClient(); $db = $connection->dbname; ?></span>
Please note that if you accidentally create a new database, strange errors may occur. Such as the following example:
<span style="font-size:14px;"><?php $connection = new MongoClient(); $db = $connection->mybiglongdbname; // do some stuff $db = $connection->mybiglongdbanme; // now connected to a different database! 注意此时选择了另一个数据库! ?></span>
Copyright statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.
The above introduces how to obtain a mongodb instance in PHP 56, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.