加入收藏 | 设为首页 | 会员中心 | 我要投稿 济源站长网 (https://www.0391zz.cn/)- 数据工具、数据仓库、行业智能、CDN、运营!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php封装的mongodb操作类代码

发布时间:2021-02-25 16:12:55 所属栏目:PHP教程 来源:网络整理
导读:核心代码 /* To change this template,choose Tools | Templates and open the template in the editor. */ class mongo_db { private $config; private $connection; private $db; private $connection_string; private $host; private $port; private $use

/* -------------------------------------------------------------------------------- DROP COLLECTION -------------------------------------------------------------------------------- Removes the specified collection from the database. Be careful because this can have some very large issues in production! /
public function drop_collection($collection = "") {
if (emptyempty($collection)) {
$this->error("No Mongo collection specified to drop from database",500);
} $this->db->{$collection}->drop();
return TRUE;
}

/* -------------------------------------------------------------------------------- CLEAR -------------------------------------------------------------------------------- Resets the class variables to default settings */
private function clear() {
$this->selects = array();
$this->wheres = array();
$this->limit = NULL;
$this->offset = NULL;
$this->sorts = array();
}

/* -------------------------------------------------------------------------------- WHERE INITIALIZER -------------------------------------------------------------------------------- Prepares parameters for insertion in $wheres array(). */
private function where_init($param) {
if (!isset($this->wheres[$param])) {
$this->wheres[$param] = array();
}
}

public function error($str,$t) {
echo $str;
exit;
}

}

?>

使用范例:

table_name)); $this->mongo_db->where($where); $order=!emptyempty($order)?array('AID'=>'DESC'):array('AID'=>'ASC');//升序降序 $infos=$this->mongo_db->listinfo($table_name,$order,$pagesize);

这篇文章就到这结束了,大家可以多学习一下

(编辑:济源站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读