Home >Backend Development >PHP Tutorial >php 56 get mongodb instance

php 56 get mongodb instance

WBOY
WBOYOriginal
2016-07-29 09:15:46907browse

To select a database, use:

<span style="font-size:14px;"><?php
$connection = new MongoClient();
$db = $connection->dbname;
?></span>

This database does not need to be built in advance, it will be created automatically when you use it.

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP library collectionNext article:PHP library collection