1 Star 0 Fork 2

我喝可乐/php_framework

forked from coolcooldee/php_framework 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Nodel.php 2.15 KB
一键复制 编辑 原始数据 按行查看 历史
coolcooldee 提交于 2013-08-26 14:32 . 初始化代码
<?php
class Nodel{
protected $table_name;
//public function cache($cached_time = 3600) {
//
// return new DBCache;
//}
protected function table($table_name=null, $db_name=null) {
$db_name = ($db_name == null) ? $GLOBALS['mongo']['MONGO_DB'] : $db_name;
$table_name = ($table_name == null) ? $this->table_name : $table_name;
if(!isset($GLOBALS['db_tmp_mongo_collection'][$db_name][$table_name])){
if(!isset($GLOBALS['db_tmp_mongo_collection'])) $GLOBALS['db_tmp_mongo_collection'] = array();
if(!isset($GLOBALS['db_tmp_mongo_collection'][$db_name])) $GLOBALS['db_tmp_mongo_collection'][$db_name] = array();
$GLOBALS['db_tmp_mongo_collection'][$db_name][$table_name] = new MongoCollection($this->db($db_name), $table_name);
}
return $GLOBALS['db_tmp_mongo_collection'][$db_name][$table_name];
}
protected function db($db_name=null) {
if(!isset($GLOBALS['db_tmp_mongo']))$this->_init();
$db_name = ($db_name == null) ? $GLOBALS['mongo']['MONGO_DB'] : $db_name;
if(!isset($GLOBALS['db_tmp_mongodb'][$db_name])){
if(!isset($GLOBALS['db_tmp_mongodb'])) $GLOBALS['db_tmp_mongodb'] = array();
if( isset( $GLOBALS['mongo']['MONGO_USERNANE'] ) && isset( $GLOBALS['mongo']['MONGO_PASSWD'] ) ){
$GLOBALS['db_tmp_mongo']->selectDB($db_name)->authenticate( $GLOBALS['mongo']['MONGO_USERNANE'], $GLOBALS['mongo']['MONGO_PASSWD'] );
$GLOBALS['db_tmp_mongodb'][$db_name] = $GLOBALS['db_tmp_mongo']->selectDB($db_name);
}else{
$GLOBALS['db_tmp_mongodb'][$db_name] = $GLOBALS['db_tmp_mongo']->selectDB($db_name);
}
}
return $GLOBALS['db_tmp_mongodb'][$db_name];
}
private function _init() {
$param = array();
if( isset( $GLOBALS['mongo']['MONGO_USERNANE'] ) && isset( $GLOBALS['mongo']['MONGO_PASSWD'] ) ){
$param = array( 'username'=> $GLOBALS['mongo']['MONGO_USERNANE'] , 'password'=>$GLOBALS['mongo']['MONGO_PASSWD'] );
}
try{
$GLOBALS['db_tmp_mongo'] = new Mongo('mongodb://'.$GLOBALS['mongo']['MONGO_HOST'].':'.$GLOBALS['mongo']['MONGO_PORT'], $param );
}catch(Exception $e){
throw new Exception('mongodb cannot connect on'.$GLOBALS['mongo']['MONGO_HOST'].':'.$GLOBALS['mongo']['MONGO_PORT']);
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cole/php_framework.git
git@gitee.com:cole/php_framework.git
cole
php_framework
php_framework
master

搜索帮助