MongoCursor Object
游標類
Mongo
Config
Table
Config
<?php
require_once
class Hrs_Mongo_Config
{
const VERSION =
const DEFAULT_HOST =
const DEFAULT_PORT =
private static $host = self::DEFAULT_HOST ;
private static $port = self::DEFAULT_PORT ;
private static $options = array(
//
);
public static $conn =
public static $defaultDb =
public static $linkStatus =
public static function set($server =
if(!$server){
$url =
}
if(is_array($server)){
if(isset($server[
self::$host = $server[
}
if(isset($server[
self::$port = $server[
}
if(isset($server[
$url =
}else{
$url =
}
}
if(is_array($options)){
foreach (self::$options as $o_k=>$o_v){
if(isset($options[$o_k]))
self::$options[$o_k] = $o_v;
}
}
try{
self::$conn = new Mongo($url
self::$linkStatus =
}catch (Exception $e){
self::$linkStatus =
}
if(isset($server[
self::selectDB($server[
}
}
public static function selectDB($database){
if($database){
try {
if(self::$linkStatus==
self::$defaultDb = self::$conn
return self::$defaultDb;
}
catch(InvalidArgumentException $e) {
throw new Zend_Exception(
}
}else{
throw new Zend_Exception(
}
}
}
Table
<?php
require_once
abstract class Hrs_Mongo_Table
{
protected $_db =
protected $_name =
protected $_data = array();
protected $c_options = array(
);
protected $u_options = array(
//
);
/*
protected $r_options = array(
);*/
protected $d_options = array(
);
protected function _setAdapter($database=
if(!$database)
throw new Zend_Exception(
Hrs_Mongo_Config::selectDB($database);
}
public function __construct() {
if(Hrs_Mongo_Config::$conn instanceof Mongo){
$name = $this
$defDb = Hrs_Mongo_Config::$defaultDb;
$this
}else{
throw new Zend_Exception(
}
}
public function insert($data){
if(!$this
$ret = $this
return $ret;
}
public function update($data
if(!$this
return $this
}
public function find($where=array()
if($this
if($limit>
$this
}else{
$this
}
}
return $this;
}
//find cursor
/*
* 獲取游標對象
*/
public function look($where=array()
if($this
if($fields){
return $where ? $this
}else{
return $where ? $this
}
}
return false;
}
public function delete($where){
if(!$this
return $this
}
public function dropMe(){
if(!$this
return $this
}
public function __toString(){
return $this
}
public function toArray(){
$tmpData = array();
foreach($this
$one_row = array();
foreach($row as $key=>$col){
$one_row[$key] = $col;
}
$one_row[
$tmpData[] = $one_row;
}
return $tmpData;
}
protected function testLink(){
return Hrs_Mongo_Config::$linkStatus ==
}
}
要點注意!!!
第一種方法
//find cursor
/*
* 獲取游標對象
*/
public function look($where=array()
if($this
if($fields){
return $where ? $this
}else{
return $where ? $this
}
}
return false;
}
第二種方法
public function find($where=array()
if($this
$this
}
return $this;
} 復制代碼 代碼如下:
/*
* 獲取游標對象
*/
public function getCursor(){
return $this
}
第二種需要的是find得到的不是數組
find($where)
From:http://tw.wingwit.com/Article/program/PHP/201311/21268.html