• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP MongoDB类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中MongoDB的典型用法代码示例。如果您正苦于以下问题:PHP MongoDB类的具体用法?PHP MongoDB怎么用?PHP MongoDB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了MongoDB类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: tearDown

 public function tearDown()
 {
     if ($this->db instanceof \MongoDB) {
         $this->db->drop();
     }
     parent::tearDown();
 }
开发者ID:alapini,项目名称:apigility-3hr-tutorial,代码行数:7,代码来源:AuthControllerWithMongoAdapterTest.php


示例2: setUp

 /**
  * @access protected
  */
 protected function setUp()
 {
     $m = new Mongo();
     $db = new MongoDB($m, "phpunit");
     $this->object = $db->selectCollection('c');
     $this->object->drop();
 }
开发者ID:redmeadowman,项目名称:mongo-php-driver,代码行数:10,代码来源:MongoCollectionTest2.php


示例3: get

 /**
  * Fetches the object pointed to by a reference
  * @link http://php.net/manual/en/mongodbref.get.php
  * @static
  * @param MongoDB $db Database to use
  * @param array $ref Reference to fetch
  * @return array|null Returns the document to which the reference refers or null if the document does not exist (the reference is broken)
  */
 public static function get($db, $ref)
 {
     if (!static::isRef($ref)) {
         return null;
     }
     return $db->selectCollection($ref[static::$refKey])->findOne(['_id' => $ref[static::$idKey]]);
 }
开发者ID:RageZBla,项目名称:mongo-php-adapter,代码行数:15,代码来源:MongoDBRef.php


示例4: __construct

 /**
  * Creates new file collections
  *
  * @param mongodb $db - Database.
  * @param string $prefix -
  * @param mixed $chunks -
  */
 public function __construct(MongoDB $db, $prefix = 'fs', $chunks = 'fs')
 {
     $this->db = $db;
     $thisName = $prefix . '.files';
     $this->chunksName = $prefix . '.chunks';
     $this->chunks = $db->selectCollection($this->chunksName);
     parent::__construct($db, $thisName);
 }
开发者ID:Wynncraft,项目名称:mongofill,代码行数:15,代码来源:MongoGridFS.php


示例5: __construct

 public function __construct(\MongoDB $db, $collection_name, array $additional_find_fields = [])
 {
     if (false === is_string($collection_name)) {
         throw new Exception('collection name must be a string');
     }
     $this->collection = $db->selectCollection($collection_name);
     $this->additional_find_fields = $additional_find_fields;
 }
开发者ID:pjullah,项目名称:repository,代码行数:8,代码来源:Repository.php


示例6: 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:buraka1,项目名称:mlazarov-rockmongo,代码行数:16,代码来源:MDb.php


示例7: __construct

 /**
  * Constructor.
  *
  * @param Connection   $connection     Connection used to create Collections
  * @param \MongoDB     $mongoDB        MongoDB instance being wrapped
  * @param EventManager $evm            EventManager instance
  * @param integer      $numRetries     Number of times to retry queries
  * @param callable     $loggerCallable The logger callable
  */
 public function __construct(Connection $connection, $mongoDB, EventManager $evm, $numRetries, $loggerCallable)
 {
     if (!is_callable($loggerCallable)) {
         throw new \InvalidArgumentException('$loggerCallable must be a valid callback');
     }
     parent::__construct($evm, $mongoDB->getDatabaseName());
     $this->loggerCallable = $loggerCallable;
 }
开发者ID:pliashkou,项目名称:mongodb,代码行数:17,代码来源:LoggableDatabase.php


示例8: setUp

 public function setUp()
 {
     parent::setUp();
     $this->mongo = new MongoDB(new \MongoClient('mongodb://localhost:27017'), 'mongo_test', new InMemoryCache());
     $this->collection = $this->mongo->selectCollection('test');
     for ($i = 0; $i < 2; $i++) {
         $this->collection->insert(['foo' => 1]);
     }
 }
开发者ID:nicklasos,项目名称:MongoCache,代码行数:9,代码来源:MongoCollectionTest.php


示例9: __construct

 /**
  * @param Client $client
  * @param \MongoDB|string $database
  */
 public function __construct(Client $client, $database)
 {
     $this->client = $client;
     if ($database instanceof \MongoDB) {
         $this->database = $database;
         $this->databaseName = $database->__toString();
     } else {
         $this->databaseName = $database;
     }
 }
开发者ID:sokil,项目名称:php-mongo,代码行数:14,代码来源:Database.php


示例10: __construct

 public function __construct($host, $port, $name, $username, $password)
 {
     try {
         $client = new \MongoClient("mongodb://{$host}:{$port}");
         $this->db = new \MongoDB($client, $name);
         $this->db->authenticate($username, $password);
     } catch (\MongoException $e) {
         die('Connection failed: ' . $e->getMessage());
     }
 }
开发者ID:OhYea777,项目名称:Framework,代码行数:10,代码来源:MongoDatabase.class.php


示例11: testTest

 public function testTest()
 {
     return;
     $mongo = new MongoDB(new \MongoClient('mongodb://localhost:27017'), 'mongo_test', new Memcache($this->memcache, 1));
     $collection = $mongo->selectCollection('test_memcache');
     $collection->insert(['foo' => 1]);
     $this->assertEquals(1, $collection->count());
     sleep(1);
     $collection->insert(['foo' => 1]);
     $this->assertEquals(2, $collection->count());
 }
开发者ID:nicklasos,项目名称:MongoCache,代码行数:11,代码来源:MemcacheTest.php


示例12: connect

 /**
  * Connects to our database
  */
 public function connect()
 {
     if (!extension_loaded('mongo')) {
         throw new EMongoException(yii::t('yii', 'We could not find the MongoDB extension ( http://php.net/manual/en/mongo.installation.php ), please install it'));
     }
     try {
         $this->_mongo = new MongoClient($this->connectionString, $this->connectOptions);
         $dbname = $this->db;
         $this->_db = $this->_mongo->{$dbname};
         $this->_db->setWriteConcern($this->options['writeConcerns'], $this->options['wTimeoutMS']);
     } catch (Exception $e) {
         throw new EMongoException(yii::t('yii', 'We could not find the MongoDB extension ( http://php.net/manual/en/mongo.installation.php ), please install it'));
     }
 }
开发者ID:blackdragon199154,项目名称:scryptmail,代码行数:17,代码来源:MongoDBConnection.php


示例13: getUser

 /**
  * Communicates with the database to log in a user.
  * 
  * @param MongoDB $db       database
  * @param string  $username username
  * @param string  $pwd      plaintext password
  *
  * @return array the database response
  */
 protected static function getUser($db, $username, $pwd)
 {
     $ns = "{$db}.system.users";
     // get the nonce
     $result = $db->command(array(MongoUtil::NONCE => 1));
     if (!$result["ok"]) {
         return $result;
     }
     $nonce = $result["nonce"];
     // create a digest of nonce/username/pwd
     $digest = md5($nonce . $username . $pwd);
     $data = array(MongoUtil::AUTHENTICATE => 1, "user" => $username, "nonce" => $nonce, "key" => $digest);
     // send everything to the db and pray
     return $db->command($data);
 }
开发者ID:kph11,项目名称:mongo-php-driver,代码行数:24,代码来源:Auth.php


示例14: __construct

 /**
  * Files as stored across two collections, the first containing file meta
  * information, the second containing chunks of the actual file. By default,
  * fs.files and fs.chunks are the collection names used.
  *
  * @link http://php.net/manual/en/mongogridfs.construct.php
  * @param MongoDB $db Database
  * @param string $prefix [optional] <p>Optional collection name prefix.</p>
  * @param mixed $chunks  [optional]
  * @throws \Exception
  */
 public function __construct(MongoDB $db, $prefix = "fs", $chunks = null)
 {
     if ($chunks) {
         trigger_error("The 'chunks' argument is deprecated and ignored", E_DEPRECATED);
     }
     if (empty($prefix)) {
         throw new \Exception('MongoGridFS::__construct(): invalid prefix');
     }
     $this->database = $db;
     $this->prefix = (string) $prefix;
     $this->filesName = $prefix . '.files';
     $this->chunksName = $prefix . '.chunks';
     $this->chunks = $db->selectCollection($this->chunksName);
     parent::__construct($db, $this->filesName);
 }
开发者ID:alcaeus,项目名称:mongo-php-adapter,代码行数:26,代码来源:MongoGridFS.php


示例15: getCollection

 public function getCollection($collName)
 {
     if (!$this->database) {
         throw new Exception\LogicException("Can't select collection as there's no database set");
     }
     return $this->database->selectCollection($collName);
 }
开发者ID:railsphp,项目名称:ar-mongo,代码行数:7,代码来源:Connection.php


示例16: getChannelCollection

 public static function getChannelCollection()
 {
     if (MongoConnector::$db == null) {
         MongoConnector::connect();
     }
     return MongoConnector::$db->selectCollection("channels");
 }
开发者ID:xpyctum,项目名称:ShogChat,代码行数:7,代码来源:MongoConnector.php


示例17: evaluate

 /**
  * Evaluates the constraint for parameter $other. Returns TRUE if the
  * constraint is met, FALSE otherwise.
  *
  * @param mixed $other Value or object to evaluate.
  * @return bool
  */
 public function evaluate($other)
 {
     $query = array('_id' => $other);
     $data = $this->db->selectCollection($this->collection)->findOne($query);
     $this->found = $data[$this->property];
     return ($this->found == $this->expected);
 }
开发者ID:rickyrobinett,项目名称:morph,代码行数:14,代码来源:DocumentPropertyEquals.php


示例18: testAuthBasic

 public function testAuthBasic()
 {
     $ok = $this->object->authenticate("testUser", "testPass");
     $this->assertEquals($ok['ok'], 1, json_encode($ok));
     $ok = $this->object->authenticate("testUser", "bar");
     $this->assertEquals($ok['ok'], 0, json_encode($ok));
 }
开发者ID:petewarden,项目名称:mongo-php-driver,代码行数:7,代码来源:AuthTest.php


示例19: 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


示例20: collection

 /**
  * Retrieves a collection by name.
  * @param  $name
  * @return MongoCollection
  */
 public function collection($name)
 {
     if ($this->collections[$name]) {
         return $this->collections[$name];
     }
     $c = $this->mongo_db->selectCollection($name);
     $this->collections[$name] = $c;
     return $c;
 }
开发者ID:jawngee,项目名称:HeavyMetal,代码行数:14,代码来源:mongodb_document_store.php



注:本文中的MongoDB类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP MongoDBRef类代码示例发布时间:2022-05-23
下一篇:
PHP MongoCursor类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap