Skip to content

Commit 472175f

Browse files
committed
Add port and use latest MCR image
Throw DB connection errors for SQL Server Use the include directive
1 parent 5cf1d72 commit 472175f

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

.github/workflows/test-phpunit.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,14 @@ jobs:
6262
- 5432:5432
6363
options: --health-cmd=pg_isready --health-interval=10s --health-timeout=5s --health-retries=3
6464
mssql:
65-
image: microsoft/mssql-server-linux:2017-latest
65+
image: mcr.microsoft.com/mssql/server:2019-latest
6666
env:
6767
SA_PASSWORD: 1Secure*Password1
6868
ACCEPT_EULA: Y
6969
MSSQL_PID: Developer
7070
ports:
7171
- 1433:1433
72+
options: --name=mssql --health-cmd="/opt/mssql-tools/bin/sqlcmd -S 127.0.0.1,1433 -U SA -P '1Secure*Password1' -Q 'SELECT 1'" --health-interval=10s --health-timeout=5s --health-retries=3
7273
redis:
7374
image: redis
7475
ports:
@@ -82,7 +83,7 @@ jobs:
8283
steps:
8384
- name: Create database for MSSQL Server
8485
if: matrix.db-platforms == 'SQLSRV'
85-
run: sqlcmd -S 127.0.0.1 -U sa -P 1Secure*Password1 -Q "CREATE DATABASE test"
86+
run: docker exec -i mssql /opt/mssql-tools/bin/sqlcmd -S 127.0.0.1,1433 -U SA -P '1Secure*Password1' -Q 'CREATE DATABASE test'
8687

8788
- name: Checkout
8889
uses: actions/checkout@v2

system/Database/SQLSRV/Connection.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ public function __construct($params)
103103
/**
104104
* Connect to the database.
105105
*
106-
* @param boolean $persistent
106+
* @param boolean $persistent
107+
*
108+
* @throws DatabaseException
109+
*
107110
* @return mixed
108111
*/
109112
public function connect(bool $persistent = false)
@@ -127,20 +130,26 @@ public function connect(bool $persistent = false)
127130
unset($connection['UID'], $connection['PWD']);
128131
}
129132

130-
if (false !== ($this->connID = sqlsrv_connect($this->hostname, $connection)))
133+
$this->connID = sqlsrv_connect($this->hostname, $connection);
134+
135+
if ($this->connID !== false)
131136
{
132-
/* Disable warnings as errors behavior. */
133-
sqlsrv_configure('WarningsReturnAsErrors', 0);
137+
sqlsrv_configure('WarningsReturnAsErrors', 1);
134138

135139
// Determine how identifiers are escaped
136140
$query = $this->query('SELECT CASE WHEN (@@OPTIONS | 256) = @@OPTIONS THEN 1 ELSE 0 END AS qi');
137141
$query = $query->getResultObject();
138142

139143
$this->_quoted_identifier = empty($query) ? false : (bool) $query[0]->qi;
140144
$this->escapeChar = ($this->_quoted_identifier) ? '"' : ['[', ']'];
145+
146+
return $this->connID;
141147
}
142148

143-
return $this->connID;
149+
// $error = $this->error();
150+
// $message = preg_replace('/(\[.+\]\[.+\](?:\[.+\])?)(.+)/', '$2', $error['message']);
151+
152+
throw new DatabaseException(var_export(sqlsrv_errors(SQLSRV_ERR_ERRORS)));
144153
}
145154

146155
/**

0 commit comments

Comments
 (0)