PHP 56 connects to mongodb database

WBOY
Release: 2016-07-29 09:15:45
Original
1083 people have browsed it

In the previous blog post, we have explained how to configure the mongodb database in Windows; now let’s implement how to connect to the database.

Connect using one of the methods listed below:

<?php
$connection = new Mongo(); // 连接到 localhost:27017
$connection = new Mongo( "mongodb://IP" ); // 连接到远程服务器 (使用默认端口: 27017)
$connection = new Mongo( "mongodb://IP:65432" ); // 链接到远程服务器,使用自定义的端口
$connection = new MongoClient(); // 连接到 localhost:27017
$connection = new MongoClient( "mongodb://IP" ); // 连接到远程服务器 (使用默认端口: 27017)
$connection = new MongoClient( "mongodb://IP:65432" ); // 链接到远程服务器,使用自定义的端口
?>
Copy after login

Copy after login
There is no need to disconnect from the server. This driver uses a persistent connection and will reuse it the next time you try to connect to the same server.

If you want to disconnect, use the following:

$connection->close();
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 PHP 56 to connect to the mongodb database, 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