我正在使用codeigniter和mongodb数据库创建应用程序.由于codeigniter不包含mongodbs驱动程序,我使用内置库连接mongodb.我用这个链接创建了mongodb configration文件和Mongo_db库.配置文件就像application\config\mongodb:
<?php
$config['default']['mongo_hostbase'] = 'localhost:27017';
$config['default']['mongo_database'] = 'test';
$config['default']['mongo_username'] = '';
$config['default']['mongo_password'] = '';
$config['default']['mongo_persist'] = FALSE;
$config['default']['mongo_persist_key'] = 'ci_persist';
$config['default']['mongo_replica_set'] = FALSE;
$config['default']['mongo_query_safety'] = 'safe';
$config['default']['mongo_suppress_connect_error'] = FALSE;
$config['default']['mongo_host_db_flag'] = FALSE;
?>
Run Code Online (Sandbox Code Playgroud)
和Mongo_db库是这样的:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Mongo_db
{
public function __construct()
{
//Check mongodb is installed in your server otherwise display an error
if ( ! class_exists('Mongo'))
{
$this->_show_error('The MongoDB PECL extension has not been installed or enabled', …Run Code Online (Sandbox Code Playgroud)