PHP throws "undefined symbol: SQLGetInstalledDrivers"
PHP Driver version or file name
sqlsrv-5.3.0
pdo_sqlsrv-5.3.0
Client operating system
CentOS Linux release 7.5.1804 (Core)
PHP version
PHP 7.1.20 (cli) (built: Jul 19 2018 10:10:15) ( NTS )
Microsoft ODBC Driver version
Name : msodbcsql17
Arch : x86_64
Version : 17.2.0.1
Release : 1
Problem description
After following the RedHat 7 guide (https://docs.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-2017#installing-the-drivers-on-red-hat-7) php throws the following warnings:
# php -v
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/sqlsrv.so' - /usr/lib64/php/modules/sqlsrv.so: undefined symbol: SQLGetInstalledDrivers in Unknown on line 0
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: SQLGetInstalledDrivers in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/ixed.5.4.lin' - /usr/lib64/php/modules/ixed.5.4.lin: undefined symbol: _zend_hash_index_update_or_next_insert in Unknown on line 0
PHP 7.1.20 (cli) (built: Jul 19 2018 10:10:15) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
Trying to execute a PHP script using the drivers results in:
Fatal error: Uncaught Error: Call to undefined function sqlsrv_connect()
Repro code or steps to reproduce
I'm not sure how to reproduce this issue as I've setup the driver successfully on two Debian 9 systems. Please let me know if you require any additional information.
Hi @matthenning
Do you have other php versions in your system? Looks like you also have troubles loading SourceGuardian /usr/lib64/php/modules/ixed.5.4.lin?
What's the output of php --ini?
The instructions in the online docs are for Red Hat 7 users. For CentOS 7, the instructions are slightly different. To install php from the "remi" repository, these are the steps for php 7.2 (change to php71 in the 5th step):
sudo su
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 remi-php72
yum update
yum install php php-pdo php-xml php-pear php-devel re2c gcc-c++ gcc
Glad to hear you have successfully installed the drivers in Debian 9 systems. But in CentOS 7 / Red Hat 7 there's an issue with PECL, and you will need a more recent GCC than the default. Please follow the instructions to get Developer Toolset 7
Did you install the drivers using pecl install or did you try the alternative way by pecl download? If you did pecl download and compile the drivers afterwards, was the build successful?
@yitam I'm having same problem also. Does sqlsrv module work with Centos 6 and PHP 7.2 ? this is the production server of my client :(
No @solcre we support Red Hat 7 / CentOS 7 but not CentOS 6.
Ouch!
@yitam is there any workaround to make it work in CentOS 6 ? I've seen some threads around but not sure if they are trustable sources.
Hi @solcre, I'm afraid you will have to compile the drivers yourself, possibly with pecl, phpize, etc.
The ODBC drivers do support both Red Hat 6 and 7
Thanks for your quick reply @yitam. I manually upgraded gcc to be able to compile the drivers myself. But the extensions are throwing some error. Here is the log:
[01-Aug-2018 00:13:18 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'sqlsrv.so' (tried: /opt/cpanel/ea-php72/root/usr/lib64/php/modules/sqlsrv.so (/opt/cpanel/ea-php72/root/usr/lib64/php/modules/sqlsrv.so: undefined symbol: _ZSt24__throw_out_of_range_fmtPKcz), /opt/cpanel/ea-php72/root/usr/lib64/php/modules/sqlsrv.so.so (/opt/cpanel/ea-php72/root/usr/lib64/php/modules/sqlsrv.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
[01-Aug-2018 00:13:18 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_sqlsrv.so' (tried: /opt/cpanel/ea-php72/root/usr/lib64/php/modules/pdo_sqlsrv.so (/opt/cpanel/ea-php72/root/usr/lib64/php/modules/pdo_sqlsrv.so: undefined symbol: _ZSt24__throw_out_of_range_fmtPKcz), /opt/cpanel/ea-php72/root/usr/lib64/php/modules/pdo_sqlsrv.so.so (/opt/cpanel/ea-php72/root/usr/lib64/php/modules/pdo_sqlsrv.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
[01-Aug-2018 00:13:18 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'sqlsrv.so' (tried: /opt/cpanel/ea-php72/root/usr/lib64/php/modules/sqlsrv.so (/opt/cpanel/ea-php72/root/usr/lib64/php/modules/sqlsrv.so: undefined symbol: _ZSt24__throw_out_of_range_fmtPKcz), /opt/cpanel/ea-php72/root/usr/lib64/php/modules/sqlsrv.so.so (/opt/cpanel/ea-php72/root/usr/lib64/php/modules/sqlsrv.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
[01-Aug-2018 00:13:18 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_sqlsrv.so' (tried: /opt/cpanel/ea-php72/root/usr/lib64/php/modules/pdo_sqlsrv.so (/opt/cpanel/ea-php72/root/usr/lib64/php/modules/pdo_sqlsrv.so: undefined symbol: _ZSt24__throw_out_of_range_fmtPKcz), /opt/cpanel/ea-php72/root/usr/lib64/php/modules/pdo_sqlsrv.so.so (/opt/cpanel/ea-php72/root/usr/lib64/php/modules/pdo_sqlsrv.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
@yitam just in case it helps:
root@whm [/home/apiclientes/public_html]# g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/4.9.3/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --disable-multilib --enable-languages=c,c++
Thread model: posix
gcc version 4.9.3 (GCC)
Hi @yitam,
I upgraded from PHP 5.6 (could've been 5.3) to 7.1. I couldn't find any left overs from the previous version.
# php --ini
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/sqlsrv.so' - /usr/lib64/php/modules/sqlsrv.so: undefined symbol: SQLGetInstalledDrivers in Unknown on line 0
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: SQLGetInstalledDrivers in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/ixed.5.4.lin' - /usr/lib64/php/modules/ixed.5.4.lin: undefined symbol: _zend_hash_index_update_or_next_insert in Unknown on line 0
Configuration File (php.ini) Path: /etc
Loaded Configuration File: /etc/php.ini
Scan for additional .ini files in: /etc/php.d
Additional .ini files parsed: /etc/php.d/20-bz2.ini,
/etc/php.d/20-calendar.ini,
/etc/php.d/20-ctype.ini,
/etc/php.d/20-curl.ini,
/etc/php.d/20-dom.ini,
/etc/php.d/20-exif.ini,
/etc/php.d/20-fileinfo.ini,
/etc/php.d/20-ftp.ini,
/etc/php.d/20-gd.ini,
/etc/php.d/20-gettext.ini,
/etc/php.d/20-iconv.ini,
/etc/php.d/20-json.ini,
/etc/php.d/20-ldap.ini,
/etc/php.d/20-mbstring.ini,
/etc/php.d/20-mcrypt.ini,
/etc/php.d/20-mysqlnd.ini,
/etc/php.d/20-odbc.ini,
/etc/php.d/20-pdo.ini,
/etc/php.d/20-phar.ini,
/etc/php.d/20-posix.ini,
/etc/php.d/20-shmop.ini,
/etc/php.d/20-simplexml.ini,
/etc/php.d/20-snmp.ini,
/etc/php.d/20-sockets.ini,
/etc/php.d/20-sqlite3.ini,
/etc/php.d/20-sqlsrv.ini,
/etc/php.d/20-sysvmsg.ini,
/etc/php.d/20-sysvsem.ini,
/etc/php.d/20-sysvshm.ini,
/etc/php.d/20-tokenizer.ini,
/etc/php.d/20-xml.ini,
/etc/php.d/20-xmlwriter.ini,
/etc/php.d/20-xsl.ini,
/etc/php.d/30-mysqli.ini,
/etc/php.d/30-pdo_mysql.ini,
/etc/php.d/30-pdo_odbc.ini,
/etc/php.d/30-pdo_sqlite.ini,
/etc/php.d/30-pdo_sqlsrv.ini,
/etc/php.d/30-wddx.ini,
/etc/php.d/30-xmlreader.ini,
/etc/php.d/40-ssh2.ini,
/etc/php.d/40-zip.ini,
/etc/php.d/sourceguardian.ini
Aren't those the exact instructions from https://docs.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-2017#installing-the-drivers-on-red-hat-7 or am I missing something? Anyway I tried them and it boiled down to:
Package php-7.1.20-1.el7.remi.x86_64 already installed and latest version
Package php-pdo-7.1.20-1.el7.remi.x86_64 already installed and latest version
Package php-xml-7.1.20-1.el7.remi.x86_64 already installed and latest version
Package 1:php-pear-1.10.5-6.el7.remi.noarch already installed and latest version
Package php-devel-7.1.20-1.el7.remi.x86_64 already installed and latest version
Package gcc-c++-4.8.5-28.el7_5.1.x86_64 already installed and latest version
Package gcc-4.8.5-28.el7_5.1.x86_64 already installed and latest version
Nothing to do
The dev tools were already upgraded:
Package devtoolset-7-7.1-4.el7.x86_64 already installed and latest version
I tried compiling the drivers myself using the pecl download way described in the docs mentioned above.
# make
/.../
Libraries have been installed in:
/root/sqlsrv-5.3.0/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Build complete.
Don't forget to run 'make test'.
# make install
Installing shared extensions: /usr/lib64/php/modules/
This still results in PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/sqlsrv.so' - /usr/lib64/php/modules/sqlsrv.so: undefined symbol: SQLGetInstalledDrivers in Unknown on line 0
I disabled SourceGuardian for now as I'm not sure whether I need it.
Hi @matthenning, yes the instructions are almost the same, except for one line and how to get the devtools.
A few more questions to try to understand what the problem is:
- What's your unixODBC version? (
odbcinst -j) -- any unixODBC related env variables set up? - Did you do this
sudo yum install unixODBC-devel? - I saw this "Libraries have been installed in: /root/sqlsrv-5.3.0/modules" -- did you compile everything as the root user? Or did you do
sudo pecl download? - What's the output of
sudo pear version? Is it linked with the latest PHP version (php -v)? - Locate where your ODBC driver is installed
odbcinst -q -d -n "ODBC Driver 17 for SQL Server"and then do something like thisldd /opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.2.so.0.1
HI @solcre , you might need to seek help somewhere else. As I mentioned before, we don't support Red Hat 6 / CentOS 6.
Hi @matthenning, please ignore my previous message. I accidentally closed this issue. Anyway, try to compile this simple c program. If unixODBC was installed properly in your system, it should work.
#include <odbcinst.h>
#include <string.h>
int main()
{
char szBuf[2001] = {'\0'}; // use a large enough buffer size
WORD cbBufMax = 2000;
WORD cbBufOut;
char *pszBuf = szBuf;
BOOL result;
// get all the names of the installed drivers delimited by null characters
result = SQLGetInstalledDrivers(szBuf, cbBufMax, &cbBufOut);
do
{
printf("driver: %s\n", pszBuf);
// get the next driver
pszBuf = strchr(pszBuf, '\0') + 1;
}
while (pszBuf[1] != '\0');
}
To compile and run this test, do the followings:
gcc -o mytest simple.c -lodbcinst
./mytest
Because I have both ODBC 13 and 17, the output of mytest is:
driver: ODBC Driver 13 for SQL Server
driver: ODBC Driver 17 for SQL Server
Please give this a try.
Hi @yitam,
looks like there is something wrong with my odbc installation. Also see answer 1 and 5.
# ./mytest
./mytest: symbol lookup error: ./mytest: undefined symbol: SQLGetInstalledDrivers
- No env variables
# env | grep ODBC
# odbcinst -j
unixODBC 2.3.1
odbcinst: symbol lookup error: odbcinst: undefined symbol: odbcinst_system_file_name
- Yes
- Everything ran as the root user, not via sudo
PEAR Version: 1.10.5
# odbcinst -q -d -n "ODBC Driver 17 for SQL Server"
Segmentation fault
I'm not really sure where to start troubleshooting this. Yum looks fine:
# yum info unixODBC-devel
Installed Packages
Name : unixODBC-devel
Arch : x86_64
Version : 2.3.1
Release : 11.el7
Size : 186 k
Repo : installed
From repo : BaseOS
Summary : Development files for programs which will use the unixODBC library
URL : http://www.unixODBC.org/
License : GPLv2+ and LGPLv2+
Description : The unixODBC package can be used to access databases through ODBC
: drivers. If you want to develop programs that will access data through
: ODBC, you need to install this package.
Available Packages
Name : unixODBC-devel
Arch : i686
Version : 2.3.1
Release : 11.el7
Size : 54 k
Repo : BaseOS/x86_64
Summary : Development files for programs which will use the unixODBC library
URL : http://www.unixODBC.org/
License : GPLv2+ and LGPLv2+
Description : The unixODBC package can be used to access databases through ODBC
: drivers. If you want to develop programs that will access data through
: ODBC, you need to install this package.
Hi @matthenning
I agree. Something is wrong with unixODBC and/or MS ODBC driver installation. Please consider uninstalling them both first.
To remove MS ODBC 17, do yum remove -y msodbcsql17
If you happen to have older versions of MS ODBC, also do yum remove -y msodbcsql
If you have installed mssql-tools, then yum remove -y mssql-tools
Then do the following:
yum remove -y unixODBC unixODBC-devel
yum -y clean all
After all this, doing odbcinst -j should return something like
bash: /usr/bin/odbcinst: No such file or directory
To reinstall, please follow the MS ODBC 17 installation instructions
Note that unixODBC will be installed by the package manager because it's a dependency.
When you're done, please try odbcinst -j and odbcinst -q -d -n "ODBC Driver 17 for SQL Server"
Hi @yitam,
thank you for your effort. Sadly I'm running into the same issue.
We decided to order new VMs and set them up from scratch, as I inherited the current ones and they seem fubar. I'll give a short feedback after I'm done whether this was in isolated issue or if it occured on the fresh system, too.
The setup went flawlessly on the fresh VMs. I think we can close this issue.
Thank you again for your help. It's greatly appreciated.