Commit 9e7a971c authored by Marco Pivetta's avatar Marco Pivetta

Merge branch 'hotfix/#777-allow-optional-host-and-server-connection-parameters'

Close #777
parents 06e64e27 470cde99
...@@ -35,24 +35,15 @@ class Driver extends AbstractSQLAnywhereDriver ...@@ -35,24 +35,15 @@ class Driver extends AbstractSQLAnywhereDriver
* {@inheritdoc} * {@inheritdoc}
* *
* @throws \Doctrine\DBAL\DBALException if there was a problem establishing the connection. * @throws \Doctrine\DBAL\DBALException if there was a problem establishing the connection.
* @throws SQLAnywhereException if a mandatory connection parameter is missing.
*/ */
public function connect(array $params, $username = null, $password = null, array $driverOptions = array()) public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
{ {
if ( ! isset($params['host'])) {
throw new SQLAnywhereException("Missing 'host' in configuration for sqlanywhere driver.");
}
if ( ! isset($params['server'])) {
throw new SQLAnywhereException("Missing 'server' in configuration for sqlanywhere driver.");
}
try { try {
return new SQLAnywhereConnection( return new SQLAnywhereConnection(
$this->buildDsn( $this->buildDsn(
$params['host'], isset($params['host']) ? $params['host'] : null,
isset($params['port']) ? $params['port'] : null, isset($params['port']) ? $params['port'] : null,
$params['server'], isset($params['server']) ? $params['server'] : null,
isset($params['dbname']) ? $params['dbname'] : null, isset($params['dbname']) ? $params['dbname'] : null,
$username, $username,
$password, $password,
...@@ -90,11 +81,16 @@ class Driver extends AbstractSQLAnywhereDriver ...@@ -90,11 +81,16 @@ class Driver extends AbstractSQLAnywhereDriver
*/ */
private function buildDsn($host, $port, $server, $dbname, $username = null, $password = null, array $driverOptions = array()) private function buildDsn($host, $port, $server, $dbname, $username = null, $password = null, array $driverOptions = array())
{ {
$host = $host ?: 'localhost';
$port = $port ?: 2638; $port = $port ?: 2638;
if (! empty($server)) {
$server = ';ServerName=' . $server;
}
return return
'LINKS=tcpip(HOST=' . $host . ';PORT=' . $port . ';DoBroadcast=Direct)' . 'HOST=' . $host . ':' . $port .
';ServerName=' . $server . $server .
';DBN=' . $dbname . ';DBN=' . $dbname .
';UID=' . $username . ';UID=' . $username .
';PWD=' . $password . ';PWD=' . $password .
......
Markdown is supported
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