Codeigniter上的MongoDB配置

时间:2018-07-10 12:43:27

标签: php mongodb codeigniter ubuntu-14.04

我是MongoDB的新手。我在本地Windows中配置了MongoDB,并且工作正常。然后我使用HP Codeigniter框架实现了应用程序。
通过关注此帖子https://www.discussdesk.com/integrate-mongodb-in-codeigniter.htm

现在我正在尝试在ubuntu 16.04中实现托管它
我安装了PHP7和Mongodb4。
及其将phpinfo()中的Mongodb配置显示为
enter image description here

和Codeigniter配置文件如下:

Mongoci.php library is:<br>
           class Mongoci extends Mongo
    {



    function __construct()
        { 
    // Fetch CodeIgniter instance
            $ci = get_instance();
    // Load Mongo configuration file
            $ci->load->config('mongoci');

    // Fetch Mongo server and database configuration
            $server = $ci->config->item('mongo_server');
            $username = $ci->config->item('mongo_username');
            $password = $ci->config->item('mongo_password');
            $dbname = $ci->config->item('mongo_dbname');
            try {
                if($ci->config->item('mongo_auth') === FALSE)
                parent::__construct("mongodb://" . $server . "/" . $dbname);
            else
                parent::__construct("mongodb://$username:$password@$server/$dbname");
                $this->db = $this->$dbname;
                } 
            catch(MongoConnectionException $e) 
                {
        //Don't show Mongo Exceptions as they can contain authentication info
                    $_error =& load_class('Exceptions', 'core');
                    exit($_error->show_error('MongoDB Connection Error', 'A MongoDB error occured while trying to connect to the database!', 'error_db'));           
                } 
            catch(Exception $e) 
                {
                    $_error =& load_class('Exceptions', 'core');
                    exit($_error->show_error('MongoDB Error',$e->getMessage(), 'error_db'));        
                }
        }
    public function cursor_data($data)
        {
            $final_array = array();
            foreach(iterator_to_array($data) as $data_array)
                {
                    $final_array[] = $data_array;
                }
            return $final_array;
        }       

}


config / mongoci.php是

    $config['mongo_server'] = 'localhost';
    $config['mongo_dbname'] = 'dbname';
    $config['mongo_auth']   = FALSE;
    $config['mongo_username'] = 'dbuser';
    $config['mongo_password'] = 'xxxxxx';


现在我的问题是当我运行应用程序时显示错误:

  

致命错误:在第3行的/var/www/html/application/libraries/Mongoci.php中找不到类'Mongo'

0 个答案:

没有答案