本文整理汇总了PHP中Mongo类的典型用法代码示例。如果您正苦于以下问题:PHP Mongo类的具体用法?PHP Mongo怎么用?PHP Mongo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mongo类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: testBasic
public function testBasic()
{
$r1 = new MongoRegex("//");
$this->assertEquals($r1->regex, "");
$this->assertEquals($r1->flags, "");
$r2 = new MongoRegex("/foo/bar");
$this->assertEquals($r2->regex, "foo");
$this->assertEquals($r2->flags, "bar");
$r3 = new MongoRegex($r2);
$this->assertEquals($r3->regex, "foo");
$this->assertEquals($r3->flags, "bar");
$stupid_str = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
$rstupid = new MongoRegex("/{$stupid_str}/flagflagflagflagflag");
$this->assertEquals($rstupid->regex, $stupid_str);
$this->assertEquals($rstupid->flags, "flagflagflagflagflag");
$m = new Mongo();
$c = $m->selectCollection('phpunit', 'regex');
$c->drop();
$c->insert(array('x' => 0, 'r1' => $r1));
$c->insert(array('x' => 1, 'r2' => $r2));
$c->insert(array('x' => 2, 'stupid' => $rstupid));
$obj = $c->findOne(array('x' => 0));
$this->assertEquals($obj['r1']->regex, "");
$this->assertEquals($obj['r1']->flags, "");
$obj = $c->findOne(array('x' => 1));
$this->assertEquals($obj['r2']->regex, "foo");
$this->assertEquals($obj['r2']->flags, "bar");
$obj = $c->findOne(array('x' => 2));
$this->assertEquals($obj['stupid']->regex, $stupid_str);
$this->assertEquals($obj['stupid']->flags, "flagflagflagflagflag");
}
开发者ID:rjonker,项目名称:mongo-php-driver,代码行数:31,代码来源:MongoRegexTest.php
示例2: __construct
function __construct($db = null, $host = null)
{
$mongo = new Mongo($host);
$database = $mongo->selectDB($db);
$this->mongo = $mongo;
$this->database = $database;
}
开发者ID:XiaoFeiFeng,项目名称:demo,代码行数:7,代码来源:DB.Mongo.php
示例3: __construct
private function __construct()
{
$con = new Mongo("mongodb://" . MONGO_HOST . ":27017");
$db = $con->selectDB(MONGO_DATABASE);
// Connect to Database
$this->mGrid = $db->getGridFS();
}
开发者ID:programster,项目名称:php-fms-test,代码行数:7,代码来源:ConnectionHandler.php
示例4: _UpdateReport
private static function _UpdateReport($url, $reportName)
{
$_host = parse_url($url, PHP_URL_HOST);
$_today = new MongoDate(strtotime('today'));
$connected = false;
while (!$connected) {
try {
$_mdb = new Mongo();
$connected = true;
} catch (MongoConnectionException $e) {
//echo "\nMongoConnectionException: ".$e->getMessage();
sleep(1);
}
}
$_reports = $_mdb->selectDB("googleproxy")->reports;
$_rowFilter = array('host' => $_host, 'date' => $_today);
$success = false;
while (!$success) {
try {
if (!$_reports->findOne($_rowFilter)) {
$_reports->insert(array_merge($_rowFilter, array(ReportType::CacheHitCount => array('count' => 0), ReportType::RequestCount => array('count' => 0))));
}
$success = true;
} catch (MongoCursorException $e) {
//echo "\nMongoCursorException: ".$e->getMessage();
sleep(1);
}
}
$_reports->ensureIndex(array('report' => 1, 'date' => 1), array('background' => true));
$_update = array('$inc' => array($reportName . '.count' => 1));
$_options['multiple'] = false;
$_reports->update($_rowFilter, $_update, $_options);
}
开发者ID:sergrin,项目名称:crawlers-il,代码行数:33,代码来源:Reporting.php
示例5: __construct
public function __construct()
{
$mongo = new Mongo();
$mongoDb = $mongo->selectDB('ContactsManager');
$this->contactsManagerCollection = new MongoCollection($mongoDb, 'Contact');
$this->contactsManagerCollection->ensureIndex(array('email' => 1), array('unique' => true, 'dropDups' => true));
}
开发者ID:lga37,项目名称:contacts,代码行数:7,代码来源:ContactMongoStorage.php
示例6: createInstance
/**
* Creates a mongo connection and connects.
*
* @throws MongoConnectionException, Exception
* @return MongoDB database object
*/
private function createInstance()
{
//Pull these from a config file
jimport('sml.smlconfig');
$conf = new SMLConfig();
$serverList = $conf->mongo_hosts;
$database = $conf->mongo_db;
$persistent = $conf->mongo_persistent;
$paired = $conf->mongo_paired;
//End config entries
if (count($serverList) > 2) {
throw new Exception("Connection can be established to 2 or fewer instances only.");
}
if (count($serverList) == 2) {
$paired = true;
$servers = implode(',', $serverList);
} else {
$servers = $serverList[0];
}
try {
$m = new Mongo($servers, true, $persistent, $paired);
$db = $m->selectDB($database);
} catch (Exception $e) {
//we should swallow this, and likely put a site down message up..
die('<pre>' . $e->getTraceAsString());
}
return $db;
}
开发者ID:spacemonkey,项目名称:sml4joomla,代码行数:34,代码来源:jmongo.php
示例7: conn
protected function conn()
{
if (!isset(self::$_db_handle[$this->db_config_name])) {
if (false == ($iconfig = C($this->db_config_name, 'db'))) {
show_error('数据库配制文件db.config.php中 ' . $this->db_config_name . ' 未设置。');
}
$DSN = 'mongodb://';
// exp: mongodb://192.168.1.222
if ($iconfig['user']) {
$DSN .= $iconfig['user'];
}
if ($iconfig['password']) {
$DSN .= ':' . $iconfig['password'];
}
if ($DSN != 'mongodb://') {
$DSN .= '@';
}
if ($iconfig['host']) {
$DSN .= $iconfig['host'];
}
if (!empty($iconfig['port'])) {
$DSN .= ':' . $iconfig['port'];
}
$mongoDB = new Mongo($DSN);
self::$_db_handle[$this->db_config_name] = $this->db = $mongoDB->selectDB($iconfig['dbname']);
} else {
$this->db = self::$_db_handle[$this->db_config_name];
}
return $this->db;
}
开发者ID:wangxian,项目名称:ePHP,代码行数:30,代码来源:modelMongodb.class.php
示例8: __construct
/**
* $dsn has to contain db_name after the host. E.g. "mongodb://localhost:27017/mongo_test_db"
*
* @static
* @param $dsn
* @param $user
* @param $password
* @return \Mongo
* @throws \Exception
*/
public function __construct($dsn, $user, $password)
{
/* defining DB name */
$this->dbName = substr($dsn, strrpos($dsn, '/') + 1);
if (strlen($this->dbName) == 0) {
throw new \Exception('Please specify valid $dsn with DB name after the host:port');
}
/* defining host */
if (false !== strpos($dsn, 'mongodb://')) {
$this->host = str_replace('mongodb://', '', $dsn);
} else {
$this->host = $dsn;
}
$this->host = rtrim(str_replace($this->dbName, '', $this->host), '/');
$options = array('connect' => TRUE);
if ($user && $password) {
$options += array('username' => $user, 'password' => $password);
}
try {
$m = new \Mongo($dsn, $options);
$this->dbh = $m->selectDB($this->dbName);
} catch (\MongoConnectionException $e) {
throw new \Exception(sprintf('Failed to open Mongo connection: %s', $e->getMessage()));
}
$this->dsn = $dsn;
$this->user = $user;
$this->password = $password;
}
开发者ID:lenninsanchez,项目名称:donadores,代码行数:38,代码来源:MongoDb.php
示例9: __construct
function __construct()
{
$this->conf = new Conf();
$m = new Mongo();
$db = $m->selectDB($this->conf->db());
$this->selfColl = $db->zone;
}
开发者ID:rebe100x,项目名称:YAKREP,代码行数:7,代码来源:zone.php
示例10: __construct
public function __construct()
{
$debugOutput = false;
$mongoDir = "/usr";
if (!file_exists($mongoDir . '/bin/mongod')) {
throw new PHPUnit_Framework_SkippedTestError('mongo daemon not found');
}
static $m;
if (!isset($m)) {
$port = Kwf_Util_Tcp::getFreePort(rand(27020, 30000));
$cmd = "php " . KWF_PATH . "/bootstrap.php test forward --controller=kwf_model_mongo_run-temp-mongo --port={$port}";
if ($debugOutput) {
echo $cmd . "\n";
$descriptorspec = array(1 => STDOUT, 2 => STDOUT);
} else {
$cmd .= " 2>&1 >/dev/null";
$descriptorspec = array(1 => array('pipe', 'w'), 2 => STDOUT);
}
self::$_proc = new Kwf_Util_Proc($cmd, $descriptorspec);
sleep(3);
$m = new Mongo("mongodb://localhost:{$port}");
register_shutdown_function(array('Kwf_Model_Mongo_TestModel', 'shutDown'));
}
$db = $m->selectDB("modeltest");
$db->selectCollection($this->_collection)->drop();
$config = array('db' => $db);
parent::__construct($config);
}
开发者ID:xiaoguizhidao,项目名称:koala-framework,代码行数:28,代码来源:TestModel.php
示例11: createConnection
protected static function createConnection()
{
$server = isset($GLOBALS['mongo_server']) ? $GLOBALS['mongo_server'] : 'mongodb://localhost:27017';
$dbName = isset($GLOBALS['mongo_db_name']) ? $GLOBALS['mongo_db_name'] : 'task_queue_tests';
$mongo = new \Mongo($server);
return $mongo->selectDb($dbName);
}
开发者ID:rybakit,项目名称:taskqueue,代码行数:7,代码来源:MongoDBQueueTest.php
示例12: registerServices
/**
* Registers the module-only services
*
* @param Phalcon\DI $di
*/
public function registerServices($di)
{
/**
* Read configuration
*/
$config = (include __DIR__ . "/config/config.php");
$di['view']->setViewsDir(__DIR__ . '/views/');
/**
* The database connection is created based on the parameters defined in the configuration file
*/
$di['db'] = function () use($config) {
return new DbAdapter(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname));
};
/**
* The mongo connection is created
*/
$di['mongo'] = function () {
$mongo = new \Mongo();
return $mongo->selectDb("biko");
};
/**
* ODM Collection Manager
*/
$di['collectionManager'] = function () {
return new CollectionManager();
};
/**
* Unique Cart ID generator
*/
$di['unique'] = function () {
return new Generator();
};
}
开发者ID:riquedesimone,项目名称:biko,代码行数:38,代码来源:Module.php
示例13: add_point
public static function add_point($lat, $lon, $point_name)
{
$m = new Mongo();
$db = $m->selectDB("your_db");
$collection = $db->your_collection;
$collection->insert(array("point_name" => $point_name, "loc" => array("lon" => $lon, "lat" => $lat)));
}
开发者ID:ew-evidence-backup,项目名称:php_boilerplate,代码行数:7,代码来源:MongoDB_GEO.php
示例14: __construct
/**
* 构造查询
*
* @param Mongo $mongo MongoDB连接
* @param string $db 数据库
* @param string $collection 集合
*/
function __construct(Mongo $mongo, $db, $collection)
{
$this->_dbName = $db;
$this->_collectionName = $collection;
$this->_db = $mongo->selectDB($this->_dbName);
$this->_collection = $mongo->selectCollection($this->_dbName, $this->_collectionName);
}
开发者ID:jango2015,项目名称:nette-mongodb-sandbox,代码行数:14,代码来源:RQuery.php
示例15: connect
public function connect()
{
// Connect to the database and return the collection
$mongo = new Mongo('mongodb://localhost');
$db = $mongo->selectDB('test');
return $db->selectCollection('locations');
}
开发者ID:himanshu0503test,项目名称:sample_php_mongo,代码行数:7,代码来源:ConnectToMongo.php
示例16: __construct
function __construct()
{
$this->conf = new Conf();
$m = new Mongo();
$db = $m->selectDB($this->conf->db());
$this->placeColl = $db->place;
$this->yakCatColl = $db->yakcat;
$this->filesourceColl = $db->filesource;
$this->title = '';
$this->content = '';
$this->thumb = '';
$this->origin = '';
$this->filesourceId = '';
$this->filesourceTitle = '';
$this->access = 1;
$this->licence = '';
$this->outGoingLink = '';
$this->yakTag = array();
$this->yakCat = array();
$this->humanCat = array();
$this->freeTag = array();
$this->creationDate = time();
$this->lastModifDate = time();
$this->location = new Location();
$this->address = new Address();
$this->formatted_address = "";
$this->contact = new Contact();
$this->status = 0;
$this->user = 0;
$this->zone = 0;
}
开发者ID:rebe100x,项目名称:YAKREP,代码行数:31,代码来源:place.php
示例17: insert_from_cursor
function insert_from_cursor()
{
$m = new Mongo("localhost");
$m->connect();
$db = $m->selectDB("test-database");
$collection = $db->successfulTweets;
$successfulTweets = $collection->find();
// echo "<pre>";
foreach ($successfulTweets as $tweet) {
// var_dump($tweet);
$text = $tweet["text"];
$author = $tweet["user_name"];
$tweet_url = "https://twitter.com/statuses/" . $tweet["tweet_id"];
$handle_url = "https://twitter.com/" . $tweet["user_name"];
if ($tweet["tweet_id"] == Null) {
$title = "<span>--manual_post<span>: " . $text;
$content = "This post was manually submitted";
$author = "--manual_post";
} else {
$title = "<span>" . $author . "</span>: " . $text . "<p> - [<a href=\"" . $tweet_url . "\" class=\"header-tweet-link\">link</a> | <a href=\"" . $handle_url . "\" class=\"header-handle-link\">@" . $author . "</a>]</p>";
$content = "<a href=\"" . $tweet_url . "\">Check out the original tweet here: https://twitter.com/statuses/" . $tweet["tweet_id"];
$author = $tweet["user_name"];
}
if ($tweet["tweeted_yet"] == True) {
// echo "Already posted";
} else {
// echo "Not yet posted";
$myPost = array('post_title' => $title, 'post_content' => $content, 'post_status' => 'publish', 'post_author' => $author);
// var_dump($myPost);
$collection->update(array('_id' => $tweet['_id']), array('$set' => array('tweeted_yet' => True)));
$newVar = wp_insert_post($myPost);
}
}
// echo "</pre>";
}
开发者ID:sjhermanek,项目名称:paypal-SE-infohub,代码行数:35,代码来源:importFromMongo.php
示例18: setUp
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
*/
protected function setUp()
{
$m = new Mongo();
$this->object = $m->selectCollection('phpunit', 'c');
$this->object->drop();
// $this->object->start = memory_get_usage(true);
}
开发者ID:redmeadowman,项目名称:mongo-php-driver,代码行数:13,代码来源:MongoCursorTest.php
示例19: __construct
/**
* 构造函数,创建Mongo操作对象,并选择库,选择集合
* @param $collection 集合名称
*/
public function __construct($collection = 'guess_you_like_document')
{
$conn = new Mongo('mongodb://othermongodb:30000');
$db = $conn->selectDB('cms');
$this->myCollection = $db->selectCollection($collection);
return $this->myCollection;
}
开发者ID:suhanyujie,项目名称:myFavorite,代码行数:11,代码来源:mongoOperate.php
示例20: __construct
/**
* Constructs a new memcache cache driver and sets its configuration.
*
* @param array $config The Memcache configuration.
*
* @return Mongo
*/
public function __construct(array $config = [])
{
$this->config = array_merge($this->config, $config);
$mongo = new \Mongo($this->config['dsn'], $this->config['options']);
$mongodb = $mongo->selectDB($this->config['db']);
$this->collection = $mongodb->selectCollection($this->config['collection']);
$this->collection->ensureIndex(['_id' => 1, 'expires' => 1], ['background' => true]);
}
开发者ID:devco,项目名称:model,代码行数:15,代码来源:Mongo.php
注:本文中的Mongo类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论