1

I have installed (again) the sqlsrv using pecl for Ubuntu 18 yet for some reason the driver is not found.

This is the error I get could not find driver.

Here are the steps I followed:

$ sudo apt-get remove php-common
$ sudo apt-get autoremove
$ sudo apt-get install php-fpm php-mbstring php-zip php-mysql php-sqlite3 php-dev php-pear php-xml


$ sudo pecl uninstall sqlsrv
$ sudo pecl uninstall pdo_sqlsrv

$ sudo pecl install sqlsrv
$ sudo pecl install pdo_sqlsrv

I created the file sqlsrv.ini with the content:

extension=pdo_sqlsrv.so
extension=sqlsrv.so

and copied it to /etc/php/7.2/cli/ and /etc/php/7.2/fpm/

here is how the php code looks:

$host = "station\SQL, port"; //azure
$db = "dbname";
$user = "user";
$pass = "pass";

try {
    $conn = new PDO("sqlsrv:Server=$host;Database=$db;LoginTimeout=60", $user, $pass);
}
catch (Exception $e) {
    echo $e->getMessage();
}

When trying to list the modules from the cli with php -m | grep sql I don't get the sqlsrv module in the list of loaded modules:

mysqli
mysqlnd
pdo_mysql
pdo_sqlite
sqlite3

Alternatively php --ri pdo_sqlsrv returns Extension 'pdo_sqlsrv' not present.

odbcinst -j returns:

unixODBC 2.3.4
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8

dpkg-query -L libodbc1 returns:

/.
/usr
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libodbc.so.2.0.0
/usr/lib/x86_64-linux-gnu/libodbccr.so.2.0.0
/usr/lib/x86_64-linux-gnu/odbc
/usr/lib/x86_64-linux-gnu/odbc/libnn.so
/usr/share
/usr/share/doc
/usr/share/doc/libodbc1
/usr/share/doc/libodbc1/NEWS.Debian.gz
/usr/share/doc/libodbc1/changelog.Debian.gz
/usr/share/doc/libodbc1/copyright
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/libodbc1
/usr/lib/x86_64-linux-gnu/libodbc.so.1
/usr/lib/x86_64-linux-gnu/libodbc.so.2
/usr/lib/x86_64-linux-gnu/libodbccr.so.1
/usr/lib/x86_64-linux-gnu/libodbccr.so.2
1

Enable the mod: sudo phpenmod sqlsrv

See this link to install driver: https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.