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

php 56 get mongodb instance

WBOY
Release: 2016-07-29 09:15:46
Original
917 people have browsed it

To select a database, use:

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

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>
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template