コード例 #1
0
ファイル: DB.php プロジェクト: nathanieltite/elefant
 /**
  * Open a database connection and add it to the pool. Accepts
  * an array of connection info taken from the global `conf()`.
  */
 public static function open($conf)
 {
     if (!self::$connections) {
         self::$connections = array();
     }
     $id = isset($conf['master']) && $conf['master'] ? 'master' : 'slave_' . count(self::$connections);
     try {
         switch ($conf['driver']) {
             case 'sqlite':
                 self::$connections[$id] = new PDO('sqlite:' . $conf['file']);
                 break;
             case 'pgsql':
                 if (strstr($conf['host'], ':')) {
                     $conf['host'] = str_replace(':', ';port=', $conf['host']);
                 }
                 self::$connections[$id] = new PDO('pgsql:host=' . $conf['host'] . ';dbname=' . $conf['name'] . ';user='******'user'] . ';password='******'pass']);
                 break;
             default:
                 if (strstr($conf['host'], ':')) {
                     $conf['host'] = str_replace(':', ';port=', $conf['host']);
                 }
                 self::$connections[$id] = new PDO($conf['driver'] . ':host=' . $conf['host'] . ';dbname=' . $conf['name'], $conf['user'], $conf['pass']);
         }
     } catch (PDOException $e) {
         self::$error = $e->getMessage();
         return false;
     }
     self::$connections[$id]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     self::$connections[$id]->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
     return true;
 }
コード例 #2
0
 /**
  * Tear down the test environment.
  */
 public function tearDown()
 {
     DB::$connections = array();
 }
コード例 #3
0
ファイル: TiendaNubeTestCase.php プロジェクト: jknox12/mirror
 private function tearDownDatabase()
 {
     DB::$connections = [];
 }