本文整理汇总了PHP中Mongo::__construct方法的典型用法代码示例。如果您正苦于以下问题:PHP Mongo::__construct方法的具体用法?PHP Mongo::__construct怎么用?PHP Mongo::__construct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mongo
的用法示例。
在下文中一共展示了Mongo::__construct方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: catch
function __construct()
{
//allow mongo to use 64bit ints
ini_set('mongo.native_long', 1);
// Fetch CodeIgniter instance
$ci = get_instance();
// Load Mongo configuration file
$ci->load->config('mongo');
// Fetch Mongo server and database configuration
$server = $ci->config->item('mongo_server');
$username = $ci->config->item('mongo_username');
$password = $ci->config->item('mongo_password');
$dbname = $ci->config->item('mongo_dbname');
try {
if ($ci->config->item('mongo_auth') === FALSE) {
parent::__construct("mongodb://" . $server . "/" . $dbname);
} else {
parent::__construct("mongodb://{$username}:{$password}@{$server}/{$dbname}");
}
$this->db = $this->{$dbname};
} catch (MongoConnectionException $e) {
//Don't show Mongo Exceptions as they can contain authentication info
$_error =& load_class('Exceptions', 'core');
exit($_error->show_error('MongoDB Connection Error', 'A MongoDB error occured while trying to connect to the database!', 'error_db'));
} catch (Exception $e) {
$_error =& load_class('Exceptions', 'core');
exit($_error->show_error('MongoDB Error', $e->getMessage(), 'error_db'));
}
}
示例2: __construct
/**
* Creates a new Mongo database connection
* @param string $server Mongo connection string, eg. mongodb://localhost:27017
* @param array $options Refer to http://www.php.net/manual/en/mongo.construct.php
* @param int $debugProfileLevel Default is 0 (Off)
*/
public function __construct($server, $options = null, $debugProfileLevel = 0)
{
parent::__construct($server, $options);
if ($debugProfileLevel > 0) {
$this->enableDebug($debugProfileLevel);
}
}
示例3: __construct
/**
* 构造函数
*
* @param array $config
* @access public
* @return void
*/
public function __construct(array $config)
{
list($dsn, $options) = self::parseConfig($config);
if (!isset($options['persist'])) {
$options['persist'] = $dsn;
}
parent::__construct($dsn, $options);
}
示例4: __construct
public function __construct($connection = 'default')
{
$this->config = new Library_config();
$this->database = $this->config->mongodb->{$connection}->database;
$host = $this->config->mongodb->{$connection}->host;
/**
* EN: This is the mongodb connection option. Eg: array('replicaSet' => true, 'connect' => false)
*/
$connection_options = array();
parent::__construct($host, $connection_options);
}
示例5: __construct
public function __construct($connectionString = null, array $options = array())
{
Shanty_Mongo::init();
// Set the server to local host if one was not provided
if (is_null($connectionString)) {
$connectionString = '127.0.0.1';
}
$options['connect'] = false;
$this->_connectionInfo = $options;
$this->_connectionInfo['connectionString'] = $connectionString;
return parent::__construct($connectionString, $options);
}
示例6: __construct
public function __construct($server = 'mongodb://localhost:27017', $options = array('connect' => false))
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
}
$this->options = array_merge(array('connect' => false, 'initialize_on_connect' => true), $options);
parent::__construct($server, $this->options);
self::$_connection = $this;
if (preg_match('|/([a-zA-Z][a-zA-Z0-9_]*)$|', $server, $matches)) {
$this->setDefaultDB($matches[1]);
}
}
示例7: open
public function open()
{
if (!$this->_connected) {
try {
//$password = Common::mysql_db_encrypt($this->password);
//parent::__construct($this->dsn, $this->username, $password, $this->options);
parent::__construct($this->server);
$this->_connected = true;
} catch (Exception $e) {
throw new Yaf_Exception('连接MongoDB失败: ' . $e->getMessage());
}
}
}
示例8: __construct
public function __construct($connectionString = null, array $options = array())
{
Shanty_Mongo::init();
// Set the server to local host if one was not provided
if (is_null($connectionString)) {
$connectionString = '127.0.0.1';
}
// Force mongo to connect only when we need to
$options['connect'] = false;
$connectionInfo = self::parseConnectionString($connectionString);
$this->_connectionInfo = array_merge($options, $connectionInfo);
return parent::__construct($connectionString, $options);
}
示例9: __construct
public function __construct()
{
$this->ci = get_instance();
$this->ci->config->load('mongo');
try {
parent::__construct(config_item('mongo_host') . ':' . config_item('mongo_port'));
} catch (MongoConnectionException $e) {
show_error("MongoDB connection failed: {$e->getMessage()}", 500);
}
if (!config_item('mongo_database')) {
show_error('mongo_database can not empty.', 500);
}
}
示例10:
function CI_Mongo()
{
$CI =& get_instance();
$CI->load->config('mongodb');
$server = $CI->config->item('host');
$dbname = $CI->config->item('database');
// Initialize MongoDB Configuration
if ($server) {
parent::__construct($server);
} else {
parent::__construct();
}
$this->db = $this->{$dbname};
}
示例11:
function CI_Mongo()
{
// Fetch CodeIgniter instance
$ci = get_instance();
// Load Mongo configuration file
$ci->load->config('mongo');
// Fetch Mongo server and database configuration
$server = $ci->config->item('mongo_server');
$dbname = $ci->config->item('mongo_dbname');
// Initialise Mongo
if ($server) {
parent::__construct($server);
} else {
parent::__construct();
}
$this->db = $this->{$dbname};
}
示例12: __construct
public function __construct($config, $connectionName)
{
/**
* Makesure Mongo extension is enabled
*/
if (!class_exists('Mongo')) {
throw new RunException('Mongo PECL extension that required by Mongodb Driver is not available.');
}
$this->config = $config;
$this->connection = $connectionName;
/**
* $this->config['options'] is the mongodb connection option. Eg: array('replicaSet' => true, 'connect' => false)
*/
try {
parent::__construct($this->config['host'], $this->config['options']);
} catch (\MongoConnectionException $e) {
RunException::outputError('Unable connect to database in <strong>' . $connectionName . '</strong> connection.');
}
}
示例13: __construct
/**
* 构造函数
*
* @param array $config
* @access public
* @return void
*/
public function __construct(array $config)
{
list($dsn, $options) = self::parseConfig($config);
parent::__construct($dsn, $options);
}
示例14: __construct
public function __construct($config = null)
{
parent::__construct($config);
$this->_rows = new Group();
$this->_rows->type('\\BlueFission\\Data\\Storage\\Mongo');
}
示例15: __construct
public function __construct()
{
$this->fp = fopen('/tmp/mongocdr.txt', 'a+');
parent::__construct();
}