欢迎来到天天文库
浏览记录
ID:63497896
大小:20.03 KB
页数:43页
时间:2021-08-24
《php实现的mongodb操作类实例_》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、php实现的mongodb操作类实例_本文实例讲解并描述了php实现的mongodb操作类。分享给大家供大家参考。具体如下:?php/**Tochangethistemplate,chooseTools
2、Templates*andopenthetemplateintheeditor.*/classmongo_db{private$config;private$connection;private$db;private$connection_string;private$host;private$port;private$user;priva
3、te$pass;private$dbname;private$persist;private$persist_key;private$selects=array();private$wheres=array();private$sorts=array();private$limit=999999;private$offset=0;private$timeout=200;private$key=0;/****CONSTRUCTOR***AutomaticallycheckiftheMongoPECLextensionhasbeeninstal
4、led/enabled.*GeneratetheconnectionstringandestablishaconnectiontotheMongoDB.*/publicfunction__construct(){if((IS_NOSQL!=1)){return;}if(!class_exists('Mongo')){//$this-error("TheMongoDBPECLextensionhasnotbeeninstalledorenabled",500);}$configs=wxcity_base::load_config("cache
5、","mongo_db");$num=count($configs['connect']);$this-timeout=trim($configs['timeout']);$keys=wxcity_base::load_config('double');$this-key=$keys['mongo_db'];$this-config=$configs['connect'][$this-key];$status=$this-connect();if($status==false){for($i=1;$i$num;$i++){$n=$this-
6、key+$i;$key=$n=$num?$n-$num:$n;$this-config=$configs['connect'][$key];$status=$this-connect();if($status!=false){$keys['mongo_db']=$key;$this-key=$key;$data="?phpreturn".var_export($keys,true).";?";file_put_contents(WHTY_PATH.'configs/double.php',$data,LOCK_EX);break;}
7、}}if($status==false){die('mongoDBnotconnect');}}function__destruct(){if((IS_NOSQL!=1)){return;}if($this-connection){$this-connection-close();}}/****CONNECTTOMONGODB***EstablishaconnectiontoMongoDBusingtheconnectionstringgeneratedin*theconnection_string()method.If'mongo_per
8、sist_key'wassettotrueinthe*configfile,establishapersistentconnection.Weallowforonlythe'persist'*optiontobesetbecausewewanttoestablishaconnectionimmediately.*/privatefunctionconnect(){$this-connection_string();$options=array('connect'=true,'timeout'=$this-timeout);try{$this
9、-connection=newMongo($this-connection_string,$options);$this-db=$this-connection-{$this-d
此文档下载收益归作者所有