The Class has changed again :
$m = new MongoDB\Driver\Manager("mongodb://alex:mypassword@10.111.0.2:27017/");
使用下面列出的其中一种方法链接:
<?php
$connection = new MongoClient(); // 连接到 localhost:27017
$connection = new MongoClient( "mongodb://example.com" ); // 连接到远程服务器 (使用默认端口: 27017)
$connection = new MongoClient( "mongodb://example.com:65432" ); // 链接到远程服务器,使用自定义的端口
?>
你并不必须手动从服务器断开连接。这个驱动使用了持久连接,并会在下次试图链接到同一服务器时重用它。
The Class has changed again :
$m = new MongoDB\Driver\Manager("mongodb://alex:mypassword@10.111.0.2:27017/");
Another way to connect, that works for me:
require 'vendor/autoload.php';//composer require "mongodb/mongodb=^1.0.0.0"
$m = new MongoDB\Client("mongodb://alex:mypassword@10.111.0.2:27017/");
echo "Connection to database successfull. <br>";