當前位置: 首頁>>代碼示例>>PHP>>正文


PHP MongoDB::execute方法代碼示例

本文整理匯總了PHP中MongoDB::execute方法的典型用法代碼示例。如果您正苦於以下問題:PHP MongoDB::execute方法的具體用法?PHP MongoDB::execute怎麽用?PHP MongoDB::execute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在MongoDB的用法示例。


在下文中一共展示了MongoDB::execute方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: onExecute

 public function onExecute(\UniMapper\Adapter\IQuery $query)
 {
     $result = $this->database->execute($query->getRaw());
     $callback = $query->callback;
     if ($callback) {
         return $callback($result);
     }
     return $result;
 }
開發者ID:bauer01,項目名稱:unimapper-mongo,代碼行數:9,代碼來源:Adapter.php

示例2: insertNext

    /**
     * 插入新的行,_id是上一行的ID加1
     *
     * @param array $attrs 新行的屬性集
     * @return boolean
     */
    function insertNext(array $attrs)
    {
        $response = $this->_db->execute('function insertObject(o, myCollection) {
			var x = db.getCollection(myCollection);
			while( 1 ) {
		        // determine next _id value to try
		        var c = x.find({},{_id:1}).sort({_id:-1}).limit(1);
		        var i = c.hasNext() ? c.next()._id + 1 : 1;
		        o._id = i;
		        x.insert(o);
		        var err = db.getLastErrorObj();
		        if( err && err.code ) {
		            if( err.code == 11000 /* dup key */ )
		                continue;
		            else
		                print("unexpected error inserting data: " + tojson(err));
		        }
		        break;
		    }
		    return o._id;
		}', array($attrs, $this->_collectionName));
        if ($response["ok"]) {
            import("@.RMongo");
            RMongo::setLastInsertId($response["retval"]);
        }
        return $response["ok"];
    }
開發者ID:jango2015,項目名稱:nette-mongodb-sandbox,代碼行數:33,代碼來源:RQuery.php

示例3: exec

 /**
  * Execute a piece of javascript code
  *
  * @param MongoDB $db DB
  * @param string $code javascript code
  * @param array $params javascript function parameters
  * @return array 
  */
 static function exec(MongoDB $db, $code, array $params = array())
 {
     $query = $db->execute($code, $params);
     if (!$query["ok"]) {
         exit("Execute failed:<font color=\"red\">" . $query["errmsg"] . "</font><br/>\n<pre>" . $code . "</pre>");
     }
     return $query["retval"];
 }
開發者ID:myurasov,項目名稱:rockmongo,代碼行數:16,代碼來源:MDb.php

示例4: testExecute

 public function testExecute()
 {
     $ret = $this->object->execute('4+3*6');
     $this->assertEquals($ret['retval'], 22, json_encode($ret));
     $ret = $this->object->execute(new MongoCode('function() { return x+y; }', array('x' => 'hi', 'y' => 'bye')));
     $this->assertEquals($ret['retval'], 'hibye', json_encode($ret));
     $ret = $this->object->execute(new MongoCode('function(x) { return x+y; }', array('y' => 'bye')), array('bye'));
     $this->assertEquals($ret['retval'], 'byebye', json_encode($ret));
 }
開發者ID:redmeadowman,項目名稱:mongo-php-driver,代碼行數:9,代碼來源:MongoDBTest.php

示例5: getDeviceFallBackTree

 public function getDeviceFallBackTree($wurflID)
 {
     $this->numQueries++;
     $response = $this->dbcon->execute('function(deviceID){ return performFallback(deviceID) }', array($wurflID));
     $data = $response['retval'];
     if ($data[count($data) - 1]['id'] != WurflConstants::$GENERIC) {
         $tw = new TeraWurfl();
         $tw->toLog("WURFL Error: device {$data[count($data) - 1]['id']} falls back on an inexistent device: {$data[count($data) - 1]['fall_back']}", LOG_ERR, __CLASS__ . '::' . __FUNCTION__);
     }
     return $data;
 }
開發者ID:vallejos,項目名稱:samples,代碼行數:11,代碼來源:TeraWurflDatabase_MongoDB.php

示例6: listCollections

 /**
  * List collections in a DB
  *
  * @param MongoDB $db DB
  * @return array<MongoCollection>
  */
 static function listCollections(MongoDB $db)
 {
     $server = MServer::currentServer();
     $names = array();
     $query = $db->execute("function (){ return db.getCollectionNames(); }", array());
     if ($query["ok"]) {
         $names = $query["retval"];
     } else {
         $colls = $db->listCollections(true);
         foreach ($colls as $coll) {
             $names[] = $coll->getName();
         }
     }
     $ret = array();
     foreach ($names as $name) {
         if ($server->shouldHideCollection($name)) {
             continue;
         }
         if (preg_match("/^system\\./", $name)) {
             continue;
         }
         $ret[] = $name;
     }
     sort($ret);
     //system collections
     if (!$server->uiHideSystemCollections()) {
         foreach ($names as $name) {
             if ($server->shouldHideCollection($name)) {
                 continue;
             }
             if (preg_match("/^system\\./", $name)) {
                 $ret[] = $name;
             }
         }
     }
     $collections = array();
     foreach ($ret as $v) {
         if ($v === "") {
             //older MongoDB version (maybe before 1.7) allow empty collection name
             continue;
         }
         $collections[] = $db->selectCollection($v);
     }
     return $collections;
 }
開發者ID:Briareos,項目名稱:rockmongo,代碼行數:51,代碼來源:MDb.php

示例7: _runJson

    private function _runJson()
    {
        $timezone = date_default_timezone_get();
        date_default_timezone_set("UTC");
        $ret = $this->_db->execute('function () {
			if (typeof(ISODate) == "undefined") {
				function ISODate (isoDateStr) {
				    if (!isoDateStr) {
				        return new Date;
				    }
				    var isoDateRegex = /(\\d{4})-?(\\d{2})-?(\\d{2})([T ](\\d{2})(:?(\\d{2})(:?(\\d{2}(\\.\\d+)?))?)?(Z|([+-])(\\d{2}):?(\\d{2})?)?)?/;
				    var res = isoDateRegex.exec(isoDateStr);
				    if (!res) {
				        throw "invalid ISO date";
				    }
				    var year = parseInt(res[1], 10) || 1970;
				    var month = (parseInt(res[2], 10) || 1) - 1;
				    var date = parseInt(res[3], 10) || 0;
				    var hour = parseInt(res[5], 10) || 0;
				    var min = parseInt(res[7], 10) || 0;
				    var sec = parseFloat(res[9]) || 0;
				    var ms = Math.round(sec % 1 * 1000);
				    sec -= ms / 1000;
				    var time = Date.UTC(year, month, date, hour, min, sec, ms);
				    if (res[11] && res[11] != "Z") {
				        var ofs = 0;
				        ofs += (parseInt(res[13], 10) || 0) * 60 * 60 * 1000;
				        ofs += (parseInt(res[14], 10) || 0) * 60 * 1000;
				        if (res[12] == "+") {
				            ofs *= -1;
				        }
				        time += ofs;
				    }
				    return new Date(time);
				};
			}
			return ' . $this->_source . ';}');
        date_default_timezone_set($timezone);
        if ($ret["ok"]) {
            return $ret["retval"];
        }
        return false;
    }
開發者ID:jango2015,項目名稱:nette-mongodb-sandbox,代碼行數:43,代碼來源:VarEval.php

示例8: execute

 /**
  * Execute
  *
  * @param  string                          $sql
  * @throws Exception\InvalidQueryException
  * @return Result
  */
 public function execute($sql)
 {
     if (!$this->isConnected()) {
         $this->connect();
     }
     try {
         if ($this->profiler) {
             $this->profiler->profilerStart($sql);
         }
         $resultResource = $this->db->execute($sql);
         if ($this->profiler) {
             $this->profiler->profilerFinish($sql);
         }
         // if the returnValue is something other than a mysqli_result, bypass wrapping it
         if (!$resultResource['ok']) {
             throw new Exception\InvalidQueryException($resultResource['errmsg']);
         }
     } catch (\Exception $e) {
         throw new Exception\InvalidQueryException($ex->getMessage(), $ex->getCode());
     }
     $resultPrototype = $this->driver->createResult($resultResource === true ? $this->resource : $resultResource);
     return $resultResource['retval'];
 }
開發者ID:pasechnik,項目名稱:mongozend,代碼行數:30,代碼來源:Connection.php

示例9: info

 /**
  * read collection information
  *
  * @param MongoDB $db database
  * @param string $collection collection name
  */
 static function info(MongoDB $db, $collection)
 {
     $ret = $db->execute('function (coll){return db.getCollection(coll).exists();}', array($collection));
     if (!$ret["ok"]) {
         exit("There is something wrong:<font color=\"red\">{$ret['errmsg']}</font>, please refresh the page to try again.");
     }
     if (!isset($ret["retval"]["options"])) {
         $ret["retval"]["options"] = array();
     }
     $isCapped = 0;
     $size = 0;
     $max = 0;
     $options = $ret["retval"]["options"];
     if (isset($options["capped"])) {
         $isCapped = $options["capped"];
     }
     if (isset($options["size"])) {
         $size = $options["size"];
     }
     if (isset($options["max"])) {
         $max = $options["max"];
     }
     return array("capped" => $isCapped, "size" => $size, "max" => $max);
 }
開發者ID:jango2015,項目名稱:nette-mongodb-sandbox,代碼行數:30,代碼來源:MCollection.php

示例10: _copyCollection

 /**
  * Enter description here...
  *
  * @param MongoDB $db
  * @param unknown_type $from
  * @param unknown_type $to
  * @param unknown_type $index
  */
 protected function _copyCollection($db, $from, $to, $index = true)
 {
     if ($index) {
         $indexes = $db->selectCollection($from)->getIndexInfo();
         foreach ($indexes as $index) {
             $options = array();
             if (isset($index["unique"])) {
                 $options["unique"] = $index["unique"];
             }
             if (isset($index["name"])) {
                 $options["name"] = $index["name"];
             }
             if (isset($index["background"])) {
                 $options["background"] = $index["background"];
             }
             if (isset($index["dropDups"])) {
                 $options["dropDups"] = $index["dropDups"];
             }
             $db->selectCollection($to)->ensureIndex($index["key"], $options);
         }
     }
     $ret = $db->execute('function (coll, coll2) { return db.getCollection(coll).copyTo(coll2);}', array($from, $to));
     return $ret["ok"];
 }
開發者ID:buraka1,項目名稱:mlazarov-rockmongo,代碼行數:32,代碼來源:BaseController.php

示例11: doCollectionStats

 /** collection statistics **/
 public function doCollectionStats()
 {
     $this->db = x("db");
     $this->collection = xn("collection");
     $this->stats = array();
     $db = new MongoDB($this->_mongo, $this->db);
     $ret = $db->execute("db.{$this->collection}.stats()");
     if ($ret["ok"]) {
         $this->stats = $ret["retval"];
         foreach ($this->stats as $index => $stat) {
             if (is_array($stat)) {
                 $this->stats[$index] = $this->_highlight($stat, "json");
             }
         }
     }
     //top
     $ret = $this->_mongo->selectDB("admin")->command(array("top" => 1));
     $this->top = array();
     $namespace = $this->db . "." . $this->collection;
     if ($ret["ok"] && !empty($ret["totals"][$namespace])) {
         $this->top = $ret["totals"][$namespace];
         foreach ($this->top as $index => $value) {
             $this->top[$index] = $value["count"];
         }
     }
     $this->display();
 }
開發者ID:jango2015,項目名稱:nette-mongodb-sandbox,代碼行數:28,代碼來源:collection.php

示例12: _exec

 /**
  * Executes a native JS MongoDB command
  * This method is not currently used for anything
  * @param string $cmd
  * @return mixed
  */
 protected function _exec($cmd)
 {
     $exec = $this->mongo->execute($cmd);
     return $exec['retval'];
 }
開發者ID:Jason3S,項目名稱:wikimarkup-wiktionary-original,代碼行數:11,代碼來源:moadmin.php

示例13: execute

 /**
  * Wrapper method for MongoDB::execute().
  *
  * @see http://php.net/manual/en/mongodb.execute.php
  * @return array
  */
 public function execute($code, array $args = [])
 {
     return $this->mongoDB->execute($code, $args);
 }
開發者ID:alcaeus,項目名稱:mongodb,代碼行數:10,代碼來源:Database.php

示例14: _call

 protected function _call($command, array $arguments = array(), array $values = NULL)
 {
     $this->_connected or $this->connect();
     extract($arguments);
     $_bm_name = isset($collection_name) ? $collection_name . '.' . $command : $command;
     if (isset($collection_name)) {
         $c = $this->_db->selectCollection($collection_name);
     }
     switch ($command) {
         case 'ensure_index':
             $r = $c->ensureIndex($keys, $options);
             break;
         case 'create_collection':
             $r = $this->_db->createCollection($name, $capped, $size, $max);
             break;
         case 'drop_collection':
             $r = $this->_db->dropCollection($name);
             break;
         case 'command':
             $r = $this->_db->command($values);
             break;
         case 'execute':
             $r = $this->_db->execute($code, $args);
             break;
         case 'batch_insert':
             $r = $c->batchInsert($values);
             break;
         case 'count':
             $r = $c->count($query);
             break;
         case 'find_one':
             $r = $c->findOne($query, $fields);
             break;
         case 'find':
             $r = $c->find($query, $fields);
             break;
         case 'group':
             $r = $c->group($keys, $initial, $reduce, $condition);
             break;
         case 'update':
             $r = $c->update($criteria, $values, $options);
             break;
         case 'insert':
             $r = $c->insert($values, $options);
             break;
         case 'remove':
             $r = $c->remove($criteria, $options);
             break;
         case 'save':
             $r = $c->save($values, $options);
             break;
         case 'get_file':
             $r = $this->gridFS()->findOne($criteria);
             break;
         case 'get_files':
             $r = $this->gridFS()->find($query, $fields);
             break;
         case 'set_file_bytes':
             $r = $this->gridFS()->storeBytes($bytes, $extra, $options);
             break;
         case 'set_file':
             $r = $this->gridFS()->storeFile($filename, $extra, $options);
             break;
         case 'remove_file':
             $r = $this->gridFS()->remove($criteria, $options);
             break;
     }
     if (isset($_bm)) {
         Profiler::stop($_bm);
     }
     return $r;
 }
開發者ID:execrot,項目名稱:mongostar,代碼行數:72,代碼來源:Connection.php

示例15: execute

 /**
  * execute.
  */
 public function execute($code, array $args = array())
 {
     $this->time->start();
     $return = parent::execute($code, $args);
     $time = $this->time->stop();
     $this->log(array('type' => 'execute', 'code' => $code, 'args' => $args, 'time' => $time));
     return $return;
 }
開發者ID:mongator,項目名稱:mongator,代碼行數:11,代碼來源:LoggableMongoDB.php


注:本文中的MongoDB::execute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。