diff --git a/.github/workflows/test-phpunit.yml b/.github/workflows/test-phpunit.yml index 5634770a2879..6a262806a1ff 100644 --- a/.github/workflows/test-phpunit.yml +++ b/.github/workflows/test-phpunit.yml @@ -82,7 +82,7 @@ jobs: steps: - name: Create database for MSSQL Server if: matrix.db-platforms == 'SQLSRV' - run: sqlcmd -S 127.0.0.1 -U sa -P 1Secure*Password1 -Q "CREATE DATABASE test" + run: sqlcmd -S 127.0.0.1,1433 -U sa -P 1Secure*Password1 -Q "CREATE DATABASE test" - name: Checkout uses: actions/checkout@v2 diff --git a/app/Views/errors/html/error_exception.php b/app/Views/errors/html/error_exception.php index e2b59d71425e..be851dda416f 100644 --- a/app/Views/errors/html/error_exception.php +++ b/app/Views/errors/html/error_exception.php @@ -19,7 +19,7 @@
-

getCode() ? ' #' . $exception->getCode() : '') ?>

+

getMessage())) ?> getMessage())) ?>" diff --git a/system/Database/SQLSRV/Connection.php b/system/Database/SQLSRV/Connection.php index 51a906ed0d58..2429cf2c3d7c 100755 --- a/system/Database/SQLSRV/Connection.php +++ b/system/Database/SQLSRV/Connection.php @@ -103,7 +103,10 @@ public function __construct($params) /** * Connect to the database. * - * @param boolean $persistent + * @param boolean $persistent + * + * @throws DatabaseException + * * @return mixed */ public function connect(bool $persistent = false) @@ -127,9 +130,11 @@ public function connect(bool $persistent = false) unset($connection['UID'], $connection['PWD']); } - if (false !== ($this->connID = sqlsrv_connect($this->hostname, $connection))) + $this->connID = sqlsrv_connect($this->hostname, $connection); + + if ($this->connID !== false) { - /* Disable warnings as errors behavior. */ + // Disable warnings as errors behavior. sqlsrv_configure('WarningsReturnAsErrors', 0); // Determine how identifiers are escaped @@ -138,9 +143,14 @@ public function connect(bool $persistent = false) $this->_quoted_identifier = empty($query) ? false : (bool) $query[0]->qi; $this->escapeChar = ($this->_quoted_identifier) ? '"' : ['[', ']']; + + return $this->connID; } - return $this->connID; + $error = $this->error(); + $message = preg_replace('/(\[.+\]\[.+\](?:\[.+\])?)(.+)/', '$2', $error['message']); + + throw new DatabaseException($message); } /**