catch exeption when opening database connection

This commit is contained in:
Uwe Steinmann 2021-08-05 08:40:13 +02:00
parent cd9d1fe25f
commit 62d9241276

View File

@ -283,22 +283,26 @@ class SeedDMS_Core_DatabaseAccess {
$dsn = $this->_driver.":".$this->_database; $dsn = $this->_driver.":".$this->_database;
break; break;
} }
/** @noinspection PhpUndefinedVariableInspection */ try {
$this->_conn = new PDO($dsn, $this->_user, $this->_passw); /** @noinspection PhpUndefinedVariableInspection */
if (!$this->_conn) $this->_conn = new PDO($dsn, $this->_user, $this->_passw);
return false; if (!$this->_conn)
return false;
switch($this->_driver) { switch($this->_driver) {
case 'mysql': case 'mysql':
$this->_conn->exec('SET NAMES utf8'); $this->_conn->exec('SET NAMES utf8');
/* Turn this on if you want strict checking of default values, etc. */ /* Turn this on if you want strict checking of default values, etc. */
// $this->_conn->exec("SET SESSION sql_mode = 'STRICT_TRANS_TABLES'"); /* $this->_conn->exec("SET SESSION sql_mode = 'STRICT_TRANS_TABLES'"); */
/* The following is the default on Ubuntu 16.04 */ /* The following is the default on Ubuntu 16.04 */
// $this->_conn->exec("SET SESSION sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'"); /* $this->_conn->exec("SET SESSION sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'"); */
break; break;
case 'sqlite': case 'sqlite':
$this->_conn->exec('PRAGMA foreign_keys = ON'); $this->_conn->exec('PRAGMA foreign_keys = ON');
break; break;
}
} catch (Exception $e) {
return false;
} }
if($this->_useviews) { if($this->_useviews) {
$tmp = $this->ViewList(); $tmp = $this->ViewList();