diff options
| author | Damien Regad <dregad@mantisbt.org> | 2018-08-03 15:15:29 +0200 |
|---|---|---|
| committer | Damien Regad <dregad@mantisbt.org> | 2018-08-03 15:15:37 +0200 |
| commit | 584a3f6f93dbd02fb7f03b52bc9562a5a0ba411a (patch) | |
| tree | a83027ab7a211a814038eb8931c5059c12cf7678 | |
| parent | 2f4f2c9b31445f719f80dfc8a1dd10a9db78c5ef (diff) | |
| parent | 2846699db2ec52e70695e700713a1b6ac4547e3c (diff) | |
| download | adodb-584a3f6f93dbd02fb7f03b52bc9562a5a0ba411a.tar.gz adodb-584a3f6f93dbd02fb7f03b52bc9562a5a0ba411a.tar.bz2 adodb-584a3f6f93dbd02fb7f03b52bc9562a5a0ba411a.zip | |
mssql: support Windows authentication (#353)
| -rw-r--r-- | drivers/adodb-mssqlnative.inc.php | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/drivers/adodb-mssqlnative.inc.php b/drivers/adodb-mssqlnative.inc.php index 4a9034aa..9fd7be67 100644 --- a/drivers/adodb-mssqlnative.inc.php +++ b/drivers/adodb-mssqlnative.inc.php @@ -483,13 +483,40 @@ class ADODB_mssqlnative extends ADOConnection { // returns true or false function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) { - if (!function_exists('sqlsrv_connect')) return null; - + if (!function_exists('sqlsrv_connect')) + { + if ($this->debug) + ADOConnection::outp('Microsoft SQL Server native driver (mssqlnative) not installed'); + return null; + } + $connectionInfo = $this->connectionInfo; $connectionInfo["Database"] = $argDatabasename; - $connectionInfo["UID"] = $argUsername; - $connectionInfo["PWD"] = $argPassword; - + if ((string)$argUsername != '' || (string)$argPassword != '') + { + /* + * If they pass either a userid or password, we assume + * SQL Server authentication + */ + $connectionInfo["UID"] = $argUsername; + $connectionInfo["PWD"] = $argPassword; + + if ($this->debug) + ADOConnection::outp('userid or password supplied, attempting connection with SQL Server Authentication'); + + } + else + { + /* + * If they don't pass either value, we wont add them to the + * connection parameters. This will then force an attempt + * to use windows authentication + */ + if ($this->debug) + ADOConnection::outp('No userid or password supplied, attempting connection with Windows Authentication'); + } + + /* * Now merge in the passed connection parameters setting */ @@ -499,10 +526,11 @@ class ADODB_mssqlnative extends ADOConnection { $connectionInfo[$parameter] = $value; } - if ($this->debug) ADOConnection::outp("<hr>connecting... hostname: $argHostname params: ".var_export($connectionInfo,true)); - if(!($this->_connectionID = sqlsrv_connect($argHostname,$connectionInfo))) + if ($this->debug) ADOConnection::outp("connecting to host: $argHostname params: ".var_export($connectionInfo,true)); + if(!($this->_connectionID = @sqlsrv_connect($argHostname,$connectionInfo))) { - if ($this->debug) ADOConnection::outp( "<hr><b>errors</b>: ".print_r( sqlsrv_errors(), true)); + if ($this->debug) + ADOConnection::outp( 'Connection Failed: '.print_r( sqlsrv_errors(), true)); return false; } |
