When loading my application after installing the drivers:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/php_pdo_sqlsrv_7_nts.so' - /usr/lib64/php/modules/php_pdo_sqlsrv_7_nts.so: undefined symbol: php_pdo_register_driver in Unknown on line 0
Can you connect to SQL Server via sqlcmd?
Yes, and I am able to successfully SELECT FROM tables, etc
PDO_SQLSRV
4.0.4 msphpsql driver release, PHP 7.0.10, CentOS Linux release 7.2.1511 (Core), non-thread safe
Doesn't seem pertinent, let me know if I can provide specific info.
@aaronsnyder php_pdo_sqlsrv_* drivers require php-pdo installed, you can install pdo extension by running sudo yum install php-pdo and then sudo yum update. Added these steps to the tutorial too, thanks for pointing it out. Let me know if it fixes the issue.
Thanks @Hadis-Fard for the quick reply!
I went to install php70w-pdo, and got the following response:
Package php70w-pdo-7.0.10-1.w7.x86_64 already installed and latest version
Nothing to do
I ran yum update as well, and everything was up to date.
Let me know if I can provide any more information.
Aaron
Load order ? pdo.so MUST be loaded before php_pdo_sqlsrv_7_nts.so
And FYI this extension is now available in my repository, see php-sqlsrv among much more extensions than other repo like webtatic.
@remicollet @Hadis-Fard
Thank you both for your help! This did the trick. I had included the extension=php_pdo_sqlsrv_7_nts.so in my php.ini at the top of the file. Switched to using a pdo_sqlsrv.ini file in php.d. Worked like a charm.
Thanks again!
Aaron
hi, I have the same issue and already try everything you said but still get the same error. I try adding extension=pdo.so to php.ini getting thi error: "PHP Warning: Module 'PDO' already loaded in Unknown on line 0" or this other "PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/pdo_sqlsrv.so' - /usr/lib64/php/modules/pdo_sqlsrv.so: undefined symbol: php_pdo_register_driver in Unknown on line 0" comment that line. both cases failed to complile a sample php file.
I've sussesfully installed php7.0 pdo_sqlvr sqlsrv via pecl and I can access mssql from ssms.
install php-pdo does not make any diference.
plase help.
@sabiansito whichLinux distribution are you using? and could you run php -m command and send me the results?
@sabiansito check extension load order, pdo.so have to be loaded "before" pdo_sqlsrv.so.
I try adding extension=pdo.so to php.ini
This is the worst place to load extension. See additional files in php.d
Long story: for security reasons, some linux distributions replace the RTLD_LAZY dlopen option (upstream default, which allow random load order) with RTLD_NOW which imply that all symbols are resolved at load time (instead of runtime) so which require to correctly manage the load order. As pdo.so is loaded from php.d/20-pdo.ini, any pdo driver must be loaded in a file with a greater prefix (the RPM use php.d/40-sqlsrv.ini, per packaging Guidelines).
P.S. don't know from which repo php-pdo is installed, but definitively, "sqlsrv" should be installed from the same repository instead of manual installation. Such issue only happen when mixing installation sources / methods.
Hi Hadis-Fard, here we go with the php -
[root@localhost ~]# vi /etc/php.ini
[root@localhost ~]# sudo echo "extension= pdo_sqlsrv.so" >> php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"
[root@localhost ~]# sudo echo "extension= sqlsrv.so" >> php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/pdo_sqlsrv.so' - /usr/lib64/php/modules/pdo_sqlsrv.so: undefined symbol: php_pdo_register_driver in Unknown on line 0
[root@localhost ~]# ^C
[root@localhost ~]# systemctl restart httpd.service
[root@localhost ~]# php -m
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/pdo_sqlsrv.so' - /usr/lib64/php/modules/pdo_sqlsrv.so: undefined symbol: php_pdo_register_driver in Unknown on line 0
[PHP Modules]
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gettext
hash
iconv
json
libxml
mbstring
mcrypt
openssl
pcntl
pcre
PDO
pdo_sqlite
Phar
posix
readline
Reflection
session
shmop
SimpleXML
sockets
SPL
sqlite3
sqlsrv
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlwriter
xsl
zlib
[Zend Modules]
Hi, remicollect, "mixing instalation resources"?
I think that culd be the problem but, still don't figure out how to solve it..
I've been following the "oficial guide" https://www.microsoft.com/en-us/sql-server/developer-get-started/php-rhel plus some extras like add yum install php-pdo and yum install yum-utils in order to run this:
yum-config-manager --enable rhel-7-server-optional-rpms.
so... what can I do?
In short, keep default php.ini
sudo echo "extension= pdo_sqlsrv.so" > $(php --ini | grep "additional .ini" | sed -e "s|.*:\s*||")/99-sqlsrv.ini
sudo echo "extension= sqlsrv.so" >> $(php --ini | grep "additional .ini" | sed -e "s|.*:\s*||")/99-sqlsrv.ini
I think that culd be the problem but, still don't figure out how to solve it..
And again, where do you get php from ?
So, what is the output of rpm -qf $(which php)
here:
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm
yum-config-manager --enable rhel-7-server-optional-rpms
yum update
yum install php70-php httpd php-cli php-common php-devel php-fpm php-mbstring php-mcrypt php-pear php-pdo
also... manually enabled remi-php70.repo from /etc/yum.repos.d, before run install php70-php
I hope this is what you are answer for.
So, you are using my repository, nothing to build from sources.
Simpler way is definitively (if you use php70-php-cli)
yum install php70-php-sqlsrv
or (if you use php-cli)
yum install php-sqlsrv
BTW, from linked MS documentation and your comment, there is a confusion.
My repository provides 2 PHP stacks
php-* in "remi-php70": base packages which updates default onesphp70-php-* in "remi-safe": SCL packages which install beside default onesAs explained by the Wizard
P.S. version 4.0.8 (stable) in stable repo, version 4.1.6.1 (devel) in testing repo.
Done, but still doesn't work.
I got this, on php.ini
extension= pdo.so
extension= pdo_sqlsrv.so
extension= sqlsrv.so
and whe I try to run a php script get this:
PHP Warning: Module 'PDO' already loaded in Unknown on line 0
PHP Warning: Module 'sqlsrv' already loaded in Unknown on line 0
PHP Warning: Module 'pdo_sqlsrv' already loaded in Unknown on line 0
If I remove extension= pdo.so from php.ini got this:
undefined symbol: php_pdo_register_driver in Unknown on line 0
Sorry, but read previous comments, answer is there, time to disconnect for me.
@remicollet Thanks for helping out. For installing PHP from your testing repo, do these make sense?
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm
subscription-manager repos --enable=rhel-7-server-optional-rpms
yum update
yum install php70-php httpd php-cli php-common php-devel php-fpm php-mbstring php-mcrypt php-pear
# ===> repo configuration
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm
subscription-manager repos --enable=rhel-7-server-optional-rpms
yum install yum-utils
# ===> permanently enable "remi-php70" which provide PHP 7.0
yum-config-manager --enable remi-php70
yum update
# ===> install PHP 7 needed extensions from "stable" repo
yum install php httpd php-cli php-common php-pdo php-fpm php-mbstring php-sqlsrv
# ===> update SQLSRV from "testing" repo (temporarily enable the testing repo)
yum --enablerepo=remi-php70-test update php-sqlsrv
SOLVE my case :
edit file
/etc/php.d/99-sqlsrv.ini
extension= sqlsrv.so
extension= pdo_sqlsrv.so
ordering.
can i get your mail...
for someone looking at this in ubuntu i solved this as well by creating the module and enabling
creating the module file and than enabling my guess is that adding it to the php.ini file was before some other required module
extension= sqlsrv.so
extension= pdo_sqlsrv.so
ln -s /etc/php/7.1/mods-available/sqlsrv.ini /etc/php/7.1/fpm/conf.d/20-sqlsrv.ini
You need to install dependency: phpX.X-common (X.X = 7.0 | 7.1 | 7.2 ...)
@ChrisFrench This was the solution I was looking for for over an hour! THX!
PS.: Also restarting apache may be necessary!
@ChrisFrench I had this working with php7.0 by adding the extension at the bottom of the php.ini file. I started the upgrade process to php7.3 and sqlsrv5.5.0preview and it was no longer working. Your solution did the trick!
Yeah, I didn't know anything about the /etc/php.d/40-sqlsrv.ini and removed the extension entries in php.ini and it started working for me.. Thanks Loetfi..
Hi, I'm running ubuntu 20.04 and Remi's answer helped me. I was calling the sql extensions by the end of the php.ini file. Instead I added a /etc/php/7.4/cli/conf.d/20-sqlsrvftw with the extensions and it worked fine =)
I had the same issue and I have changed the way of including .so files. I haven't added directly in php.ini. Its a wrong approach. I have created .ini files inside
"/etc/php.d"
with this command
echo extension=sqlsrv.so >> php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"/20-sqlsrv.ini
echo extension=pdo_sqlsrv.so >> php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"/30-pdo_sqlsrv.ini
This will solve the issue.
Please check the online documentation, which is kept up-to-date.
Most helpful comment
Load order ? pdo.so MUST be loaded before php_pdo_sqlsrv_7_nts.so