__construct() public method

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.
示例#1
0
文件: Instance.php 项目: pdedkov/db
 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
0
 /**
  * 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
0
 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
0
 /**
  */
 public function unserialize($data)
 {
     list($this->dbname, $this->_cArgs) = unserialize($data);
     parent::__construct($this->_cArgs[0], $this->_cArgs[1]);
 }