Skip to content

Commit

Permalink
Merge pull request #3426 from Icinga/feature/add-support-for-the-sqls…
Browse files Browse the repository at this point in the history
…rv-extension-3320

Add support for the sqlsrv extension
  • Loading branch information
lippserd authored Apr 24, 2018
2 parents af75c43 + b14b61d commit 37aeb83
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 9 additions & 3 deletions library/Icinga/Application/Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,20 @@ public static function hasDatabaseSupport()
/**
* Return whether it's possible to connect to a MSSQL database
*
* Checks whether the mssql pdo extension has been loaded and Zend framework adapter for MSSQL is available
* Checks whether the mssql/dblib pdo or sqlsrv extension has
* been loaded and Zend framework adapter for MSSQL is available
*
* @return bool
*/
public static function hasMssqlSupport()
{
return (static::extensionLoaded('mssql') || static::extensionLoaded('pdo_dblib'))
&& static::classExists('Zend_Db_Adapter_Pdo_Mssql');
if ((static::extensionLoaded('mssql') || static::extensionLoaded('pdo_dblib'))
&& static::classExists('Zend_Db_Adapter_Pdo_Mssql')
) {
return true;
}

return static::extensionLoaded('sqlsrv') && static::classExists('Zend_Db_Adapter_Sqlsrv');
}

/**
Expand Down
13 changes: 11 additions & 2 deletions library/Icinga/Data/Db/DbConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,23 @@ private function connect()
switch ($this->dbType) {
case 'mssql':
$adapter = 'Pdo_Mssql';
$pdoType = $this->config->get('pdoType', 'dblib');
$pdoType = $this->config->get('pdoType');
if (empty($pdoType)) {
if (extension_loaded('sqlsrv')) {
$adapter = 'Sqlsrv';
} else {
$pdoType = 'dblib';
}
}
if ($pdoType === 'dblib') {
// Driver does not support setting attributes
unset($adapterParamaters['persistent']);
unset($adapterParamaters['options']);
unset($adapterParamaters['driver_options']);
}
$adapterParamaters['pdoType'] = $pdoType;
if (! empty($pdoType)) {
$adapterParamaters['pdoType'] = $pdoType;
}
$defaultPort = 1433;
break;
case 'mysql':
Expand Down

0 comments on commit 37aeb83

Please sign in to comment.