Skip to content

Commit

Permalink
Throw DB connection errors for SQL Server
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed Apr 12, 2021
1 parent 587270f commit 36a43f3
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions system/Database/SQLSRV/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit 36a43f3

Please sign in to comment.