jericho0702 发表于 2017-12-16 10:39:47

CI框架使用扩展mongodb和memcache

  1、最好单独写一个配置文件来存储mongodb的配置,为了以后加入多台mongodb做准备
  

//这个文件的名字叫做config.default.php  class
Config_mongodb {// User库 Config_db::$user[$index]                   //在index.php 文件里边。define('CONFIG_DIR',dirname(dirname__FILE__)).'/config');定一下,然后包含下include_once(CONFIG_DIR.'/config.default.php')  

    static $count = array(  

// User库 seg_user Config_db::$user  0 => array(
  'db_ip' => '127.0.0.1',
  'db_user' => '用户名',
  'db_port' => '27017',
  'db_password' => '自己的密码'
  'db_name' => '表',
  'charset' => 'utf8'
  ),
  

  );
  

  
}
  

  2、在libraries里边添加一个Mongo_db.php操作类(CI的)自己写的也好
  3、项目里边就可以使用
  
  

$this->load->library("Mongo_db");//看类里边的操作就可以了$data['upday'] = ("Ymd");  

$mongo->where(array('devid' => $params['devid']));  

$mongo->update($collection, $data);        

  memcache怎么操作
  

$this->load->driver('cache', array('adapter' => 'memcached'));  
$cache
= $this->cache->memcached->get($cacheId);  

  
$
this->cache->memcached->save($cacheId, $row, $this->_data_expire_time);  

//另可以设置个参数,是否使用缓存,和缓存使用的时间         
页: [1]
查看完整版本: CI框架使用扩展mongodb和memcache