设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 手机 数据
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php封装的mongodb操作类代码(2)

发布时间:2021-02-23 11:22 所属栏目:121 来源:网络整理
导读:/* -------------------------------------------------------------------------------- SELECT FIELDS -------------------------------------------------------------------------------- Determine which fiel

/* -------------------------------------------------------------------------------- SELECT FIELDS -------------------------------------------------------------------------------- Determine which fields to include OR which to exclude during the query process. Currently,including and excluding at the same time is not available,so the $includes array will take precedence over the $excludes array. If you want to only choose fields to exclude,leave $includes an empty array(). @usage: $this->mongo_db->select(array('foo','bar'))->get('foobar'); /
public function select($includes = array(),$excludes = array()) {
if (!is_array($includes)) {
$includes = array();
}
if (!is_array($excludes)) {
$excludes = array();
}
if (!emptyempty($includes)) {
foreach ($includes as $col) {
$this->selects[$col] = 1;
}
} else {
foreach ($excludes as $col) {
$this->selects[$col] = 0;
}
} return($this);
}

/* -------------------------------------------------------------------------------- WHERE PARAMETERS -------------------------------------------------------------------------------- Get the documents based on these search parameters. The $wheres array should be an associative array with the field as the key and the value as the search criteria. @usage = $this->mongo_db->where(array('foo' => 'bar'))->get('foobar'); */
public function where($wheres = array()) {
foreach ((array)$wheres as $wh => $val) {
$this->wheres[$wh] = $val;
} return($this);
}

/* -------------------------------------------------------------------------------- WHERE_IN PARAMETERS -------------------------------------------------------------------------------- Get the documents where the value of a $field is in a given $in array(). @usage = $this->mongo_db->where_in('foo',array('bar','zoo','blah'))->get('foobar'); */
public function where_in($field = "",$in = array()) {
$this->where_init($field);
$this->wheres[$field]['$in'] = $in;
return($this);
}

/* -------------------------------------------------------------------------------- WHERE_NOT_IN PARAMETERS -------------------------------------------------------------------------------- Get the documents where the value of a $field is not in a given $in array(). @usage = $this->mongo_db->where_not_in('foo','blah'))->get('foobar'); */
public function where_not_in($field = "",$in = array()) {
$this->where_init($field);
$this->wheres[$field]['$nin'] = $in;
return($this);
}

/* -------------------------------------------------------------------------------- WHERE GREATER THAN PARAMETERS -------------------------------------------------------------------------------- Get the documents where the value of a $field is greater than $x @usage = $this->mongo_db->where_gt('foo',20); */
public function where_gt($field = "",$x) {
$this->where_init($field);
$this->wheres[$field]['$gt'] = $x;
return($this);
}

/* -------------------------------------------------------------------------------- WHERE GREATER THAN OR EQUAL TO PARAMETERS -------------------------------------------------------------------------------- Get the documents where the value of a $field is greater than or equal to $x @usage = $this->mongo_db->where_gte('foo',20); */
public function where_gte($field = "",$x) {
$this->where_init($field);
$this->wheres[$field]['$gte'] = $x;
return($this);
}

/* -------------------------------------------------------------------------------- WHERE LESS THAN PARAMETERS -------------------------------------------------------------------------------- Get the documents where the value of a $field is less than $x @usage = $this->mongo_db->where_lt('foo',20); */
public function where_lt($field = "",$x) {
$this->where_init($field);
$this->wheres[$field]['$lt'] = $x;
return($this);
}

/* -------------------------------------------------------------------------------- WHERE LESS THAN OR EQUAL TO PARAMETERS -------------------------------------------------------------------------------- Get the documents where the value of a $field is less than or equal to $x @usage = $this->mongo_db->where_lte('foo',20); */
public function where_lte($field = "",$x) {
$this->where_init($field);
$this->wheres[$field]['$lte'] = $x;
return($this);
}

(编辑:ASP站长网)

网友评论
推荐文章
    热点阅读