How to connect to MSSQL Server with PHP from Ubuntu 18.04?-ThrowExceptions

Exception or error:

I want to establish a MSSQL Connection from Ubunutu 18.04. It was quite hard to get this set up, but know it works so far that I can use sql_srv class or pdo class.
But when I want to connect, the connection fails with error

Array ( [0] => Array ( [0] => 01000 [SQLSTATE] => 01000 [1] => 0 [code] => 0 [2] => [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 13 for SQL Server' : file not found [message] => [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 13 for SQL Server' : file not found ) ).

How can I resolve this issue and what does this error mean?
I’ve installed ODBC 17.

 odbcinst -j
unixODBC 2.3.7
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8

And the nano /etc/odbcinst.ini shows:

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

What should I do to connect with MSSQL Server 2014 from ubuntu 18.04?

How to solve:

via this three pages I could install the correct Driver Version:

Pecl install sqlsrv returns No releases available for package

Treiber für runterladen

sudo bash -c "echo > /etc/php/7.2/mods-available/sqlsrv.ini"
sudo ln -s /etc/php/7.2/mods-available/sqlsrv.ini /etc/php/7.2/apache2/conf.d/sqlsrv.ini
sudo ln -s /etc/php/7.2/mods-available/sqlsrv.ini /etc/php/7.2/cli/conf.d/sqlsrv.ini
sudo bash -c "echo > /etc/php/7.2/mods-available/pdo_sqlsrv.ini"
sudo ln -s /etc/php/7.2/mods-available/pdo_sqlsrv.ini /etc/php/7.2/apache2/conf.d/pdo_sqlsrv.ini
sudo ln -s /etc/php/7.2/mods-available/pdo_sqlsrv.ini /etc/php/7.2/cli/conf.d/pdo_sqlsrv.ini

sudo systemctl restart apache2


Use Microsoft Drivers for PHP for Microsoft SQL Server. You will find detailed installation instructions there.

Leave a Reply

Your email address will not be published. Required fields are marked *