Skip to content

Commit 2e2d01b

Browse files
authored
Feature/sqlsrv (#132)
* Add sqlsrv extension * Add sqlsrv instructions and info to Readme * Fix bug caused by incorrect spacing * Add ext-sqlsrv.ini - Update Readme * Enable sqlsrv tests - Add test for pdo_sqlsrv Co-authored-by: Aaron Breuer <[email protected]>
1 parent 7d28209 commit 2e2d01b

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

Readme.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ memory_limit=128M
7373
| PostgreSQL | `${bref:extra.pgsql-php-74}` | |
7474
| Redis | `${bref:extra.redis-php-74}` | |
7575
| Scrypt | `${bref:extra.scrypt-php-74}` | |
76-
| SQLSRV | `${bref:extra.sqlsrv-php-74}` | `extension=/opt/bref-extra/sqlsrv.so` |
77-
| SQLSRV (PDO) | `${bref:extra.sqlsrv-php-74}` | `extension=/opt/bref-extra/pdo_sqlsrv.so` |
76+
| SQLSRV | `${bref:extra.sqlsrv-php-74}` | |
7877
| UUID | `${bref:extra.uuid-php-74}` | |
7978
| Xdebug | `${bref:extra.xdebug-php-74}` | |
8079
| Yaml | `${bref:extra.yaml-php-74}` | |
@@ -122,7 +121,7 @@ The easiest way review those is to download the [`snowflake_odbc` directory](htt
122121

123122
The SQL Server layer includes both the SQLSRV extension and the PDO_SQLSRV extension ([source](https://github.com/microsoft/msphpsql)).
124123
If you are unsure of which extension to use, this [stackoverflow post](https://stackoverflow.com/questions/11614536/sqlsrv-driver-vs-pdo-driver-for-php-with-ms-sql-server) may be helpful.
125-
In addition to enabling the chosen extension in your `php.ini`, you must set the environment variable `ODBCSYSINI: /opt/microsoft/conf/`
124+
You need to set the environment variable `ODBCSYSINI: /opt/microsoft/conf/`
126125
in your `serverless.yaml` in order to tell unixODBC to load the required ini files.
127126

128127
## Docker images

layers/sqlsrv/Dockerfile

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ RUN pecl install -f pdo_sqlsrv
1717
RUN cp /opt/bref/lib/php/extensions/no-debug-non-zts-*/sqlsrv.so /tmp/sqlsrv.so
1818
RUN cp /opt/bref/lib/php/extensions/no-debug-non-zts-*/pdo_sqlsrv.so /tmp/pdo_sqlsrv.so
1919

20+
RUN echo $'extension=/opt/bref-extra/sqlsrv.so\n\
21+
extension=/opt/bref-extra/pdo_sqlsrv.so' > /tmp/ext.ini
22+
23+
RUN echo $'[ODBC Driver 17 for SQL Server]\
24+
Driver = ODBC Driver 17 for SQL Server\n\
25+
Description = My ODBC Driver 17 for SQL Server\n\
26+
Trace = No' > /tmp/odbc.ini
2027
RUN echo $'[ODBC Driver 17 for SQL Server]\n\
21-
Driver = ODBC Driver 17 for SQL Server\n\
22-
Description = My ODBC Driver 17 for SQL Server\n\
23-
Trace = No' > /tmp/odbc.ini
24-
RUN echo $'[ODBC Driver 17 for SQL Server]\n\
25-
Description = Microsoft ODBC Driver 17 for SQL Server\n\
26-
Driver = /opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.6.so.1.1\n\
27-
UsageCount = 1' > /tmp/odbcinst.ini
28+
Description = Microsoft ODBC Driver 17 for SQL Server\n\
29+
Driver = /opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.6.so.1.1\n\
30+
UsageCount = 1' > /tmp/odbcinst.ini
2831

2932
FROM scratch
3033

@@ -46,6 +49,7 @@ COPY --from=ext /usr/lib64/libltdl* /opt/bref/lib64/
4649

4750
COPY --from=ext /tmp/sqlsrv.so /opt/bref-extra/sqlsrv.so
4851
COPY --from=ext /tmp/pdo_sqlsrv.so /opt/bref-extra/pdo_sqlsrv.so
52+
COPY --from=ext /tmp/ext.ini /opt/bref/etc/php/conf.d/ext-sqlsrv.ini
4953

5054
COPY --from=ext /tmp/odbc.ini /opt/microsoft/conf/odbc.ini
5155
COPY --from=ext /tmp/odbcinst.ini /opt/microsoft/conf/odbcinst.ini

layers/sqlsrv/test.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<?php
22

3-
exit(0);
4-
// TODO enable this test
5-
63
// This test is for sqlsrv.so
74
if (!function_exists($func = 'sqlsrv_connect')) {
85
echo sprintf('FAIL: Function "%s" does not exit.', $func).PHP_EOL;
96
exit(1);
107
}
118

9+
// This test is for pdo_sqlsrv.so
10+
if (!extension_loaded('pdo_sqlsrv')) {
11+
echo sprintf('FAIL: PDO sqlsrv extension not loaded').PHP_EOL;
12+
exit(1);
13+
}
14+
1215
exit(0);

0 commit comments

Comments
 (0)