我正在使用 mongodb 和 zendframework 2 做项目,所以在这里我在构造函数中创建连接
private $conn;
public function __construct(){
$this->conn = new \MongoClient('mongodb://example.com:27017', array("connect" => TRUE));
}
它包含几个操作来执行数据库操作,如 createdb、dropdb、renamedb 一样明智。所以我在 __distruct() 方法中关闭了该连接
public function __destruct(){
$this->conn->close();
}
我的代码工作正常。但我想知道这样可以吗?