<?php
class DBConnection {
const HOST = 'localhost';
const PORT = 27017;
const DBNAME = 'lib';
private static $instance;
public $connection;
public $database;
private function _construct()
{
$connectionString = sprintf('mongodb://%s:%d', DBConnection::HOST, DBConnection::PORT);
try {
$this->connection = new Mongo($connectionString); $this->database = $this->connection-> selectDB(DBConnection::DBNAME);
} catch (MongoConnectionException $e) {
throw $e;
}
}
static public function instantiate()
{
if (!isset(self::$instance)) {
$class = __CLASS__;
self::$instance = new $class;
}
return self::$instance;
}
public function getCollection($name)
{
return $this->database->selectCollection($name);
}
}
帮助pleaseee
答案 0 :(得分:0)
你有一个错字:__construct
有两个_
,你只有一个。