コード例 #1
0
 public function __construct(ParamsContainer $paramsContainer)
 {
     $host = $paramsContainer->getParam('database_host');
     $this->dbName = $paramsContainer->getParam('test_database_name');
     $user = $paramsContainer->getParam('database_user');
     $password = $paramsContainer->getParam('database_password');
     $dsn = "mysql:host={$host}";
     $opt = array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC);
     try {
         $this->pdo = new \PDO($dsn, $user, $password, $opt);
     } catch (\PDOException $e) {
         throw new DatabaseException('Can not create test database connection');
     }
 }
コード例 #2
0
 public function __construct(ParamsContainer $paramsContainer, $isTestMode = false)
 {
     $this->dbHelper = new DBHelper();
     try {
         $host = $paramsContainer->getParam('database_host');
         $name = $isTestMode ? $paramsContainer->getParam('test_database_name') : $paramsContainer->getParam('database_name');
         $user = $paramsContainer->getParam('database_user');
         $password = $paramsContainer->getParam('database_password');
         $dsn = "mysql:host={$host};dbname={$name}";
         $opt = array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC);
         $this->pdo = new \PDO($dsn, $user, $password, $opt);
     } catch (\Exception $e) {
         die($e->getMessage());
     }
 }