PHP 中使用 MongoDB

Installation and setting

  • Installation mongo.so, run as follow:

     git clone https://github.com/mongodb/mongo-php-driver
     cd mongo-php-driver
     phpize 
     ./configure
     make
     sudo make install
    
  • Then add

      extension=mongo.so
    

    to your php.ini file.

note:if you can‘t find any php.ini in your computer, try to search php.ini.default, and rename it to php.ini.

  sudo cp /etc/php.ini.default /etc/php.ini
  • Tips

(1) when you change the php.ini file, should restart apache

    sudo apachectl restart

(2) You can check the php setting by this:

    <?php phpinfo(); ?>

Use mongodb in codeigniter

  • fetch codeigniter-mongodb-library

      git clone https://github.com/cp0000/codeigniter-mongodb-library.git
    
  • Then copy the mongodb.php into cofig folder, copy Mongo_db.php into the libraries

  • Modify autoload.php, make sure load the mongoddb.

      $autoload[‘libraries‘] = array(‘mongo_db‘, ‘session‘, ‘user_agent‘);
    
  • Now you can use the mongodb in the codeigniter project;

      public function index()
      {
           $this->mongo_db->insert (‘User‘, array (
                            ‘user_name‘    => ‘chengpei‘,
                            ‘create_time‘  => date (‘Y-m-d H:i:s‘)
                            ));
      }

PHP 中使用 MongoDB,布布扣,bubuko.com

PHP 中使用 MongoDB

上一篇:联想笔记本电脑安装Ubuntu18.04系统


下一篇:Oracle使用技巧及PL/SQL Developer配置