Creates a new database connection object
public __construct ( string $server = 'mongodb://localhost:27017', array $options = ['connect' => true] ) | ||
$server | string | - The server name. server should have the form: mongodb://[username:password@]host1[:port1][,host2[:port2:],...]/db |
$options | array | - An array of options for the connection. |
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()); } }
/** * 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); }
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); }
/** */ public function unserialize($data) { list($this->dbname, $this->_cArgs) = unserialize($data); parent::__construct($this->_cArgs[0], $this->_cArgs[1]); }