msphpsql: Unable to load dynamic library '/usr/lib/php/20160303/pdo_sqlsrv.so' - /usr/lib/php/20160303/pdo_sqlsrv.so: undefined symbol: php_pdo_register_driver in Unknown on line 0

SQL Server version

Microsoft SQL Server 2017 (RTM) - 14.0.1000.169 (X64) Aug 22 2017 17:04:49 Copyright © 2017 Microsoft Corporation Express Edition (64-bit) on Windows 10 Pro 10.0 <X64> (Build 16299: )

Client operating system

Ubuntu 16.04

PHP version

PHP 7.1.15

Problem description

I have installed pdo_sqlsrv via sudo pecl install pdo_sqlsrv and added it to php.ini with

echo "extension=/usr/lib/php/20160303/pdo_sqlsrv.so" >> /etc/php/7.1/fpm/php.ini
echo "extension=/usr/lib/php/20160303/pdo_sqlsrv.so" >> /etc/php/7.1/cli/php.ini

php -v returns

PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php/20160303/pdo_sqlsrv.so’ - /usr/lib/php/20160303/pdo_sqlsrv.so: undefined symbol: php_pdo_register_driver in Unknown on line 0

pdo_sqlsrv also does not show up in phpinfo(). Can anyone help me fix this?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 20 (7 by maintainers)

Most upvoted comments

Hi @niheno

For security reasons, since the latest version we have changed to immediate binding, thus affecting how our drivers are loaded. Please remove the lines concerning pdo_sqlsrv.so in your php.ini files and follow the instructions here.

Hope this helps.

Hi @yitam

Thank you very much for taking the time to help! I managed to solve the problem. I followed the instructions but had to do one more thing:

It was neccessary to copy /etc/php/7.1/cli/conf.d/30-pdo_sqlsrv.ini to /etc/php/7.1/fpm/conf.d for pdo_sqlsrv to show up in phpinfo and for my Laravel application to be able to use it.

Note: On Ubuntu 18.04, this error occurs if extension=pdo_sqlsrv.so is loaded before extension=pdo.so.

The proper place to put

extension=sqlsrv.so
extension=pdo_sqlsrv.so

is not in /etc/php/7.2/fpm/php.ini and /etc/php/7.2/cli/php.ini but in /etc/php/7.2/mods-available/pdo.ini, after extension=pdo.so

@NickGiacopuzzi It looks like the driver you are trying to load is the thread safe version (it has a _ts in the name instead of _nts). If you installed PHP using your package manager, you have a non-thread safe version of PHP and you need php_sqlsrv_71_nts.so instead. (The nts version of the driver is packaged along with the ts version.)

Using the non-thread safe version will not fix the original error however, because the original error occurs when PHP tries to load pdo_sqlsrv before pdo itself. Full instructions for loading the pdo and pdo_sqlsrv extensions are available here.