Several problems with php connecting to mongoDB

WBOY
Release: 2016-07-29 09:14:46
Original
1343 people have browsed it

There are many connection methods on the Internet, so I won’t go into details here. I mainly record the problems encountered.

You can use the following statement when selecting a database:

$mongo = new Mongo("mongodb://127.0.0.1:27017/admin:admin");

$db = $mongo- >dbName.

There is a problem at this time. Under normal circumstances, this way of writing can get the database, but if the name of the database has special characters, for example, the database name is: edu-dashi, then write it in this way An error will be reported, so it must be written in another way:

$db = $mongo->selectDB("edu-dashi");

Similarly, if the collection name contains special characters, then It should be obtained as follows:

$collection = $db->selectCollection("collection");

If no selection conditions are added, the data can be obtained normally, as long as any selection is added condition, the data cannot be obtained. This may be the problem, please add:

ini_set('mongo.long_as_object', 1);

The above introduces several problems in connecting mongoDB with PHP, 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