← ServerPilot Docs

How to Connect to Microsoft SQL Server from PHP

To communicate with a Microsoft SQL Server (MSSQL) database, ServerPilot supports the ODBC extension in all PHP versions. Starting with PHP 7.0, ServerPilot supports the PDO_DBLIB extension for communicating with MSSQL. Also starting with PHP 7.0, Microsoft has resumed development of the PHP SQLSRV extension.

Connecting to MSSQL Using the PHP SQLSRV Extension

In 2016, Microsoft resumed development of the PHP SQLSRV extension. Therefore, this may be the best way to interact with Microsoft SQL Server from your PHP apps.

Learn more about installing the PHP SQLSRV extension.

Connecting to MSSQL Using ODBC

To connect to MSSQL using ODBC, you should first install the unixODBC package on your server by logging in as root and running the following command:

sudo apt-get install unixodbc

Once installed, you can configure an ODBC driver in the file /etc/odbcinst.ini and an ODBC data source in /etc/odbc.ini.

More information is available in the PHP ODBC documentation.

Connecting to MSSQL Using PDO_DBLIB

On PHP 7.0, you can use PDO_DBLIB to access both Microsoft SQL Server and Sybase databases. This extension uses the FreeTDS library. For more information, see the PDO_DBLIB documentation.

Connecting to MSSQL Using the mssql Extension

The PHP mssql extension is only supported on Windows, not on Ubuntu or other Linux distributions, and so is not supported by ServerPilot. If your code currently uses the mssql extension and you're moving it to a server managed by ServerPilot, you'll need to update your code to connect to MSSQL over ODBC or using PDO_DBLIB.

Last updated: February 18, 2017

Launch your first site in 5 minutes