Add timeout parameter for database connection

This commit is contained in:
Frédéric Guillot
2018-02-14 10:18:27 -08:00
parent b096e907cf
commit 0d578171fe
9 changed files with 78 additions and 57 deletions

View File

@@ -42,6 +42,7 @@ class Postgres extends Base
$dsn = 'pgsql:dbname='.$settings['database'];
$username = null;
$password = null;
$options = array();
if (! empty($settings['username'])) {
$username = $settings['username'];
@@ -59,7 +60,11 @@ class Postgres extends Base
$dsn .= ';port='.$settings['port'];
}
$this->pdo = new PDO($dsn, $username, $password);
if (! empty($settings['timeout'])) {
$options[PDO::ATTR_TIMEOUT] = $settings['timeout'];
}
$this->pdo = new PDO($dsn, $username, $password, $options);
if (isset($settings['schema_table'])) {
$this->schemaTable = $settings['schema_table'];