致命错误:在第55行的\ lib \ dbconnection.php中的非对象上调用成员函数selectCollection()

时间:2013-11-19 02:40:21

标签: mongodb

<?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

1 个答案:

答案 0 :(得分:0)

你有一个错字:__construct有两个_,你只有一个。