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
; 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:
......
......@@ -146,7 +146,13 @@ class AdapterFactory
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);
......@@ -160,12 +166,14 @@ class AdapterFactory
// 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% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment