Skip to content
Snippets Groups Projects
Commit 738bc206 authored by Horacio Degiorgi's avatar Horacio Degiorgi Committed by Demian Katz
Browse files

Allow port configuration for database adapter (#1008)

parent a4832e67
No related merge requests found
...@@ -450,6 +450,14 @@ sms = enabled ...@@ -450,6 +450,14 @@ sms = enabled
; This section needs to be changed to match your database connection information ; This section needs to be changed to match your database connection information
[Database] [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 database = mysql://root@localhost/vufind
; If your database (e.g. PostgreSQL) uses a schema, you can set it here: ; If your database (e.g. PostgreSQL) uses a schema, you can set it here:
......
...@@ -146,7 +146,13 @@ class AdapterFactory ...@@ -146,7 +146,13 @@ class AdapterFactory
list($type, $details) = explode('://', $connectionString); list($type, $details) = explode('://', $connectionString);
preg_match('/(.+)@([^@]+)\/(.+)/', $details, $matches); preg_match('/(.+)@([^@]+)\/(.+)/', $details, $matches);
$credentials = isset($matches[1]) ? $matches[1] : null; $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; $dbName = isset($matches[3]) ? $matches[3] : null;
if (strstr($credentials, ':')) { if (strstr($credentials, ':')) {
list($username, $password) = explode(':', $credentials, 2); list($username, $password) = explode(':', $credentials, 2);
...@@ -160,12 +166,14 @@ class AdapterFactory ...@@ -160,12 +166,14 @@ class AdapterFactory
// Set up default options: // Set up default options:
$options = [ $options = [
'driver' => $this->getDriverName($type), 'driver' => $this->getDriverName($type),
'hostname' => $host, 'hostname' => isset($host) ? $host : null,
'username' => $username, 'username' => $username,
'password' => $password, 'password' => $password,
'database' => $dbName 'database' => $dbName
]; ];
if (!empty($port)) {
$options['port'] = $port;
}
return $this->getAdapterFromOptions($options); return $this->getAdapterFromOptions($options);
} }
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment