Exemplo n.º 1
0
 /**
  * Construct for this class
  *
  * @access public
  *
  * @param array $config configuration array
  *
  * @result void
  * @throws Exception
  */
 public function __construct(array $config = [])
 {
     parent::__construct($config);
     try {
         if (empty($config['options'])) {
             $config['options'] = null;
         }
         $this->conn = new \PDO($config['connectionString'], $config['username'], $config['password'], $config['options']);
     } catch (Exception $e) {
         if (!array_key_exists('ignoreFail', $config) || !$config['ignoreFail']) {
             throw new Exception('Connect to DB failed: ' . $e->getMessage());
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Construct MongoDB
  *
  * @access public
  *
  * @param array $config configuration array
  *
  * @result void
  * @throws \MongoConnectionException
  * @throws \Micro\base\Exception
  */
 public function __construct(array $config = [])
 {
     parent::__construct($config);
     if (!empty($config['dbname'])) {
         $this->dbName = $config['dbname'];
     } else {
         throw new Exception('MongoDB database name not defined!');
     }
     try {
         if (!empty($config['connectionString'])) {
             $this->conn = new \MongoClient($config['connectionString'], $config['options']);
         } else {
             $this->conn = new \MongoClient();
         }
     } catch (Exception $e) {
         if (!$config['ignoreFail']) {
             throw new Exception('MongoDB error connect to database');
         }
     }
 }