Skip to content

Commit

Permalink
Allow port configuration for database adapter (#1008)
Browse files Browse the repository at this point in the history
  • Loading branch information
horaciod authored and demiankatz committed Jul 28, 2017
1 parent 29aa2c9 commit 7756037
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
8 changes: 8 additions & 0 deletions config/vufind/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,14 @@ sms = enabled

; This section needs to be changed to match your database connection information
[Database]
; Connection string format is [platform]://[username]:[password]@[host]:[port]/[db]
; where:
; [platform] = database platform (mysql, oci8 or pgsql)
; [username] = username for connection
; [password] = password for connection (optional)
; [host] = host of database server
; [port] = port of database server (optional)
; [db] = database name
database = mysql://root@localhost/vufind

; If your database (e.g. PostgreSQL) uses a schema, you can set it here:
Expand Down
14 changes: 11 additions & 3 deletions module/VuFind/src/VuFind/Db/AdapterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,13 @@ public function getAdapterFromConnectionString($connectionString,
list($type, $details) = explode('://', $connectionString);
preg_match('/(.+)@([^@]+)\/(.+)/', $details, $matches);
$credentials = isset($matches[1]) ? $matches[1] : null;
$host = isset($matches[2]) ? $matches[2] : null;
if (isset($matches[2])) {
if (strpos($matches[2], ':') !== false) {
list($host, $port) = explode(':', $matches[2]);
} else {
$host = $matches[2];
}
}
$dbName = isset($matches[3]) ? $matches[3] : null;
if (strstr($credentials, ':')) {
list($username, $password) = explode(':', $credentials, 2);
Expand All @@ -160,12 +166,14 @@ public function getAdapterFromConnectionString($connectionString,
// Set up default options:
$options = [
'driver' => $this->getDriverName($type),
'hostname' => $host,
'hostname' => isset($host) ? $host : null,
'username' => $username,
'password' => $password,
'database' => $dbName
];

if (!empty($port)) {
$options['port'] = $port;
}
return $this->getAdapterFromOptions($options);
}
}

0 comments on commit 7756037

Please sign in to comment.