本文整理汇总了PHP中MongoClient::__construct方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoClient::__construct方法的具体用法?PHP MongoClient::__construct怎么用?PHP MongoClient::__construct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoClient
的用法示例。
在下文中一共展示了MongoClient::__construct方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($config = array(), $options = array('connect' => true))
{
try {
$this->_config($config);
// настраиваем тестовое окружение
$connection = defined('TESTING_IS_GOING_ON') && TESTING_IS_GOING_ON && !empty($this->_config['test']) ? $this->_config['test'] : $this->_config['server'];
$server = '';
if (!empty($connection['user'])) {
$server .= $connection['user'];
}
if (!empty($connection['password'])) {
$server .= ":{$connection['password']}";
}
if (!empty($server)) {
$server .= "@";
}
$server .= "{$connection['host']}:{$connection['port']}";
$server = "mongodb://{$server}";
// соединяемся
parent::__construct($server, $options);
if (!empty($connection['db'])) {
$this->_Db = new \MongoDb($this, $connection['db']);
if (!empty($this->_config['collection'])) {
$this->_Collection = new \MongoCollection($this->_Db, $this->_config['collection']);
}
}
} catch (\MongoException $e) {
throw new Exception($e->getMessage());
}
}
示例2: __construct
/**
* Tries to connect to a MySQL Server
*/
public function __construct($db_host, $db_user, $db_pass, $db_name)
{
$this->dbName = $db_name;
if ($db_user != "" || $db_pass != "") {
$mongoAuth = $uri = $db_user . ":" . $db_pass . "@";
}
$uri = "mongodb://" . $mongoAuth . $db_host . "/" . $db_name;
parent::__construct($uri);
}
示例3: __construct
public function __construct($connectionString = null, array $options = array())
{
if (is_null($connectionString)) {
$connectionString = '127.0.0.1';
}
// $options['connect'] = false;
$this->_connectionInfo = $options;
$this->_connectionInfo['connectionString'] = $connectionString;
return parent::__construct($connectionString, $options);
}
示例4: unserialize
/**
*/
public function unserialize($data)
{
list($this->dbname, $this->_cArgs) = unserialize($data);
parent::__construct($this->_cArgs[0], $this->_cArgs[1]);
}