Welcome to the Slackware Documentation Project

Connect to Microsoft SQL Server with ODBC and PHP

Microsoft SQL Server is a relational database management system developed by Microsoft.

This article will describe how to set up unixODBC and PHP drivers to connect to MS SQL server.

Installing unixODBC

unixODBC is an open source project that implements the ODBC API

Best way to install unixODBC is from slackbuilds.org.

If you have sbopkg installed this is as easy as executing the below command:

 sbopkg -i unixODBC 
unixODBC conflicts with libiodbc in Slackware, so if you remove unixODBC, you will have to re-install libiodbc!

Installing Microsoft OBDC Drivers

The official ODBC Drivers can be downloaded from Microsoft: download link

Microsoft ODBC Driver 13.1

The version that i've tried and works was the Debian 8 packages

I've installed them by extracting the deb files using 7z and then copying the contents into the same temporary directory to allow me to create a package using makepkg.

OBDC Configuration

/etc/odbcinst.ini

[ODBC Driver 13 for SQL Server]
Description=Microsoft ODBC Driver 13 for SQL Server
Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.1.so.6.0

/etc/odbc.ini

[mssql]
Driver=ODBC Driver 13 for SQL Server
Server=tcp:YOUR_SERVER_NAME_OR_IP_ADDRESS
Database=YOUR_DATABASE

Microsoft Drivers for PHP for SQL Server

The drivers are only supported on PHP7+, so the assumption is that you are either on Slackware64-current (>=2018) or you have built and installed PHP7 manually.

The easiest way to install the drivers are to use PECL

pecl install sqlsrv
pecl install pdo_sqlsrv

Alternatively you can get the official drivers from github and build it yourself: https://github.com/Microsoft/msphpsql

Check the installation using php -i|grep “sqlsrv support” you should see something like this:

bash-4.4$ php -i|grep "sqlsrv support"
pdo_sqlsrv support => enabled
sqlsrv support => enabled

In Other Languages
Translations of this page?:
QR Code
QR Code howtos:databases:microsoft_drivers_for_php_for_sql_server (generated for current page)