[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.

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


[ODBC Driver 13 for SQL Server]
Description=Microsoft ODBC Driver 13 for SQL Server


Driver=ODBC Driver 13 for SQL Server

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
 howtos:databases:microsoft_drivers_for_php_for_sql_server ()