3
votes

I have overlook at this issue Linux - PHP 7.0 and MSSQL (Microsoft SQL)

and I am sure did exactly what MS told me to do in this page installing-the-drivers-on-red-hat-7 howevey, i stiil got the error when type 'php -v':

PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_sqlsrv.so' (tried: /usr/lib64/php/modules/pdo_sqlsrv.so (/usr/lib64/php/modules/pdo_sqlsrv.so: undefined symbol: php_pdo_register_driver), /usr/lib64/php/modules/pdo_sqlsrv.so.so (/usr/lib64/php/modules/pdo_sqlsrv.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

PHP 7.2.10 (cli) (built: Sep 15 2018 07:10:58) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.10, Copyright (c) 1999-2018, by Zend Technologies

I never modify the php.ini,

[user@tssvr php.d]$ pwd

/etc/php.d

[user@tssvr php.d]$ ls

20-sqlsrv.ini ctype.ini fileinfo.ini gmp.ini mbstring.ini pdo.ini shmop.ini tokenizer.ini xmlwriter.ini 30-pdo_sqlsrv.ini curl.ini ftp.ini iconv.ini mysqli.ini pdo_mysql.ini simplexml.ini xml.ini xsl.ini bz2.ini dom.ini gd.ini intl.ini opcache-default.blacklist pdo_sqlite.ini sockets.ini xmlreader.ini zip.ini calendar.ini exif.ini gettext.ini json.ini opcache.ini phar.ini sqlite3.ini xml_wddx.ini

[user@tssvr php.d]$ cat 20-sqlsrv.ini

extension=sqlsrv.so

[user@tssvr php.d]$ cat 30-pdo_sqlsrv.ini

extension=pdo_sqlsrv.so

it seems that the sqlsrv.so is good, but the pho_sqlsrv.so just can't work correctly,,although i notice that double 'so' appear: 'pdo_sqlsrv.so.so' , can any guys can help me through this ,many thanks.

3
Ever find a solution?Jwags
I'm having this exact issue.Matt Wohler
I'm having this exact issue...Walter Cejas

3 Answers

1
votes

The proper order to load the modules is:

extension=pdo.so
extension=pdo_sqlsrv.so
extension=sqlsrv.so

One can either put these into one .ini file - or use numbered .ini files.

Loading them in alphabetical order (which is the default) won't work.

0
votes

Type in terminal linux centos 7 :

  1. php --ini
  2. find /etc/php.d/20-pdo.ini
  3. Edit the file and append extension=sqlsrv.so extension=pdo_sqlsrv.so

note: comment extension extension=sqlsrv.so , extension=pdo_sqlsrv.so in /etc/php.ini

  1. reboot system
  2. php -m - you see loaded module
0
votes

I ran into the same issue with Ubuntu 18.04 and 20.xx. I finally got it to work on Ubuntu 18.04 and pretty sure this will work on 20.xx as well.

This is for PHP 7.1 so if you are not using 7.4 or 8.0 you will have to specify the version in pecl.

pecl install sqlsrv-5.7.0preview
pecl install pdo_sqlsrv-5.7.0preview
printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/7.1/mods-available/sqlsrv.ini
printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/7.1/mods-available/pdo_sqlsrv.ini
phpenmod -v 7.1 sqlsrv pdo_sqlsrv
service apache2 restart

The trick that got everything working was the printf and phpenmod command. You still need to add the extension to your php.ini file as well. Not sure if the order really matters but the driver does not appear to get installed properly using the pecl installer.

After restarting apache I can now see pdo_sqlsrv listed in php.ini and my php application can connect to the local Microsoft SQL server.

BTW, I got this working on WSL2 for Windows.