Commit c9594979 authored by Juozas Kaziukenas's avatar Juozas Kaziukenas

Fixed PdoSqlsrv connection DSN

parent 84770cd5
...@@ -29,11 +29,7 @@ namespace Doctrine\DBAL\Driver\PDOSqlsrv; ...@@ -29,11 +29,7 @@ namespace Doctrine\DBAL\Driver\PDOSqlsrv;
class Driver implements \Doctrine\DBAL\Driver class Driver implements \Doctrine\DBAL\Driver
{ {
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['dbname'])) {
$driverOptions['Database'] = $params['dbname'];
}
return new \Doctrine\DBAL\Driver\PDOConnection( return new \Doctrine\DBAL\Driver\PDOConnection(
$this->_constructPdoDsn($params), $this->_constructPdoDsn($params),
$username, $username,
...@@ -49,24 +45,20 @@ class Driver implements \Doctrine\DBAL\Driver ...@@ -49,24 +45,20 @@ class Driver implements \Doctrine\DBAL\Driver
*/ */
private function _constructPdoDsn(array $params) private function _constructPdoDsn(array $params)
{ {
$dsn = 'sqlsrv:server=('; $dsn = 'sqlsrv:server=';
if (isset($params['host'])) { if (isset($params['host'])) {
$dsn .= $params['host']; $dsn .= $params['host'];
} }
$dsn .= ')';
if (stripos($dsn, '\sqlexpress') !== false)
{
$dsn = str_ireplace('\sqlexpress', '', $dsn);
$dsn .= '\sqlexpress';
}
$dsn = str_ireplace('localhost', 'local', $dsn);
if (isset($params['port']) && !empty($params['port'])) { if (isset($params['port']) && !empty($params['port'])) {
$dsn .= ',' . $params['port']; $dsn .= ',' . $params['port'];
} }
if (isset($params['dbname'])) {
$dsn .= ';Database=' . $params['dbname'];
}
return $dsn; return $dsn;
} }
......
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