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