Home  >  Article  >  Backend Development  >  PHP 56 connects to mongodb database

PHP 56 connects to mongodb database

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

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" ); // 链接到远程服务器,使用自定义的端口
?>


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();

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.

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