{"id":294,"date":"2017-11-12T16:48:05","date_gmt":"2017-11-12T15:48:05","guid":{"rendered":"https:\/\/www.riedmann.it\/blog\/?p=294"},"modified":"2017-11-12T16:48:05","modified_gmt":"2017-11-12T15:48:05","slug":"debian-9-stretch-php-7-and-microsoft-sql-server-access","status":"publish","type":"post","link":"https:\/\/blog.riedmann.it\/?p=294","title":{"rendered":"Debian 9 Stretch, PHP 7 and Microsoft SQL Server access"},"content":{"rendered":"<p>Microsoft supports SQL Server access from Linux and PHP 7, but unfortunately not with Debian 9 Stretch, but only for Debian 8 (and Ubuntu 15.10, Ubuntu 16.10, Ubuntu 6.04, RedHat 7 and MacOS).<\/p>\n<p>See <a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/connect\/php\/installation-tutorial-linux-mac\" rel=\"noopener\" target=\"_blank\">https:\/\/docs.microsoft.com\/en-us\/sql\/connect\/php\/installation-tutorial-linux-mac<\/a><\/p>\n<p>I have tried to use the PDO Sybase drivers (package php7.0-sybase), but was not able to connect.<\/p>\n<p>Then I found the page <a href=\"https:\/\/github.com\/Microsoft\/msphpsql\/releases\" rel=\"noopener\" target=\"_blank\">https:\/\/github.com\/Microsoft\/msphpsql\/releases<\/a> and have done the following:<\/p>\n<p><code>pecl install sqlsrv-5.1.1preview<br \/>\npecl install pdo_sqlsrv-5.1.1preview<\/code><\/p>\n<p>The build failed until I installed the package unixodbc-dev<br \/>\n<code>apt-get install unixodbc-dev<\/code><\/p>\n<p>To enable the both modules in Apache2, I have done also the following:<br \/>\n<code>cd \/etc\/php\/7.0\/mods-available<br \/>\ncp pdo_dblib.ini pdo_sqlsrv.ini<br \/>\ncp pdo_dblib.ini sqlsrv.ini<\/code><br \/>\nchanged the contents of the files to list the appropriate -so file (pdo_sqlsrv.so and sqlsrv.so),<br \/>\n<code>cd \/etc\/php\/7.0\/apache2\/conf.d<br \/>\nln -s \/etc\/php\/7.0\/mods-available\/sqlsrv.ini 20-sqlsrv.ini<br \/>\nln -s \/etc\/php\/7.0\/mods-available\/pdo_sqlsrv.ini 20-pdo_sqlsrv.ini<\/code><br \/>\nand restarted Apache2.<\/p>\n<p>Now, my test function returned that the ODBC driver was missing.<br \/>\nI have downloaded then the Debian 8 version and installed the driver and the tools:<br \/>\n<code>wget https:\/\/packages.microsoft.com\/debian\/8\/prod\/pool\/main\/m\/msodbcsql\/msodbcsql_13.1.9.1-1_amd64.deb<br \/>\nwget https:\/\/packages.microsoft.com\/debian\/8\/prod\/pool\/main\/m\/mssql-tools\/mssql-tools_14.0.7.0-1_amd64.deb<br \/>\napt-get install unixodbc<br \/>\ndpkg -i msodbcsql_13.1.9.1-1_amd64.deb<br \/>\ndpkg -i mssql-tools_14.0.7.0-1_amd64.deb<\/code><\/p>\n<p>After this, I was able to connect to the SQL server and run a select statement.<\/p>\n<p><code>$conn = new PDO(\"sqlsrv:Server=$myserverName;Database=$myDB\", $myUser, $myPass);<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Microsoft supports SQL Server access from Linux and PHP 7, but unfortunately not with Debian 9 Stretch, but only for Debian 8 (and Ubuntu 15.10, Ubuntu 16.10, Ubuntu 6.04, RedHat 7 and MacOS). See https:\/\/docs.microsoft.com\/en-us\/sql\/connect\/php\/installation-tutorial-linux-mac I have tried to use the PDO Sybase drivers (package php7.0-sybase), but was not able to connect. Then I found [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-294","post","type-post","status-publish","format-standard","hentry","category-linux-networking"],"_links":{"self":[{"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=\/wp\/v2\/posts\/294","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=294"}],"version-history":[{"count":1,"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=\/wp\/v2\/posts\/294\/revisions"}],"predecessor-version":[{"id":295,"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=\/wp\/v2\/posts\/294\/revisions\/295"}],"wp:attachment":[{"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}