Msphpsql: SQLGetDiagField in Unknown on line 0

Created on 22 Jul 2016  Â·  16Comments  Â·  Source: microsoft/msphpsql

I get this error

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/php_sqlsrv.so' - /usr/lib64/php/modules/php_sqlsrv.so: undefined symbol: SQLGetDiagField in Unknown on line 0

Im using

Linux centos7.localdomain 3.10.0-327.22.2.el7.x86_64 #1 SMP Thu Jun 23 17:05:11 UTC 2016 x86_64
Apache/2.4.6 (CentOS) PHP/7.0.9
php_sqlsrv_7_nts.so 4.0.1

Regards

Most helpful comment

It seems the extension rely on symbol from libmsodbcsql-13.0.s0.0.0 against which the extension is not linked. Perhaps it expects to "dlopen" open it at runtime.

This is simply not supported on Fedora/Redhat/CentOS build (and probably other distro official packages), where all PHP extensions are loaded using RTLD_NOW (instead of RTLD_LAZY, for security reason), which means ALL symbols must be resolved at load time.

Workaround (to be tried), use
LD_PRELOAD=/path/to/libmsodbcsql-13.0.s0.0.0 php ...

BTW, objdump shows this library exports SQLGetDiagFieldW (not SQLGetDiagField)

Summary: getting "binaries" object is the worst way to install things on Linux. The clean way is: build it on the target OS, and distribute a clean RPM.

All 16 comments

Hello @sirio3mil ,
Can you confirm that the ODBC Driver is installed by running the following?
odbcinst -q -d -n "ODBC Driver 13 for SQL Server"
Let me know what your output looks like.

Yes, it looks like this

[ODBC Driver 13 for SQL Server]
Description= Microsoft ODBC Driver 13 for SQL Server
Driver=/opr/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.s0.0.0
Threading=1
UsageCount=1

Regards

@sirio3mil It seems like you are trying load php_sqlsrv.so not php_sqlsrv_7_nts.so, Did you rename it? Check out our getting started guide and try the instructions on a fresh machine and let us know how it goes. https://github.com/Azure/msphpsql/blob/PHP-7.0-Linux/LinuxTutorial.md

@meet-bhagdev Yes, I rename it, but I always rename it on windows systems. Tomorrow I wil try to install all again, but everything works ok, and I use provided script to install odbc and it works fine without any error (by the way great job with this script I installed in other machine this driver manually and was a headache).

I let you know with tomorrow tests.

Do you see the ‘sqlsrv’ module in the list of php modules, using this command:

$ ./php-7.0.9/sapi/cli/php -d"extension_dir=./php-7.0.9/modules" -d"extension=php_sqlsrv.so" -m

Did you install PHP from source or from a package manager?

@meet-bhagdev I'm using remi-php70 repo, I use this repo in other machine with ODBC driver 13 but through php_odbc.so and works fine.

The proper command for me is:

# php -d"extension_dir=/usr/lib64/php/modules" -d"extension=php_sqlsrv.so" -m

And result is the same

[root@centos7 ~]# php -d"extension_dir=/usr/lib64/php/modules" -d"extension=php_sqlsrv.so" -m PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/php_sqlsrv.so' - /usr/lib64/php/modules/php_sqlsrv.so: undefined symbol: SQLGetDiagField in Unknown on line 0 Violación de segmento

I use CentOs cuz yum is great, but I could understand that if I use this repo maybe this driver not work properly.

It seems the extension rely on symbol from libmsodbcsql-13.0.s0.0.0 against which the extension is not linked. Perhaps it expects to "dlopen" open it at runtime.

This is simply not supported on Fedora/Redhat/CentOS build (and probably other distro official packages), where all PHP extensions are loaded using RTLD_NOW (instead of RTLD_LAZY, for security reason), which means ALL symbols must be resolved at load time.

Workaround (to be tried), use
LD_PRELOAD=/path/to/libmsodbcsql-13.0.s0.0.0 php ...

BTW, objdump shows this library exports SQLGetDiagFieldW (not SQLGetDiagField)

Summary: getting "binaries" object is the worst way to install things on Linux. The clean way is: build it on the target OS, and distribute a clean RPM.

@remicollet @sirio3mil point taken. We are constantly improving the driver and will look into this. Should we have any questions, we will let you know.

@sirio3mil do you get the same error when connecting through sqlcmd?

Hi @meet-bhagdev,

[root@localhost ~]# sqlcmd -H 10.192._._ -U sa -P '*_'
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : TCP Provider: Error code 0x274D.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
[root@localhost ~]# ping 10.192._.

PING * (_) 56(84) bytes of data.
64 bytes from 10.192._.
: icmp_seq=1 ttl=126 time=0.784 ms

It's our development server and it is properly configured, I don't know why report this error. This is the test you need?

Regards

@sirio3mil What version of SQL Server are you using?

Hi @meet-bhagdev,

This server is a Microsoft SQL Server 2014 (SP1-CU6) (KB3144524) - 12.0.4449.0 (X64) Apr 13 2016 12:41:07 Copyright (c) Microsoft Corporation Standard Edition (64-bit) on Windows NT 6.3 (Build 9600: ) (Hypervisor).

But I can try in 2008, 2012 or 2016. we have several servers.

Otherwise I'm installing all following your manual, but it is a slow process :-)

I will let you know.

Regards

Same for us here.

root@dev-vm:/usr/lib/php# sqlcmd -H 192.168.* -U sa
Password:
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : TCP Provider: Error code 0x274D.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
root@dev-vm:/usr/lib/php# ping 192.168.

PING 192.168.* (192.168._) 56(84) bytes of data.
64 bytes from 192.168.
*_: icmp_seq=1 ttl=128 time=2.95 ms

Trying to connect to MSSQL v9.00.3033.00

Database is working OK, we've tried with FreeTDS and tsql utility from the same client:

root@dev-vm:/usr/lib/php# tsql -S 192.168.*** -U sa
Password:
locale is "LC_CTYPE=en_US.UTF-8;LC_NUMERIC=it_IT.UTF-8;LC_TIME=it_IT.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=it_IT.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=it_IT.UTF-8;LC_NAME=it_IT.UTF-8;LC_ADDRESS=it_IT.UTF-8;LC_TELEPHONE=it_IT.UTF-8;LC_MEASUREMENT=it_IT.UTF-8;LC_IDENTIFICATION=it_IT.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1> select @@VERSION
2> go

Microsoft SQL Server 2005 - 9.00.3033.00 (Intel X86)
Dec 6 2006 17:53:12
Copyright (c) 1988-2005 Microsoft Corporation
Enterprise Edition on Windows NT 5.2 (Build 3790: Service Pack 2)

(1 row affected)

Hi @meet-bhagdev,

On same machine I just uninstalled php package and build my own php and driver copy (odbc driver installation untouched).

Everything go well. It's really hard to maintenance but works for test. I will post in my blog (in spanish) installation process cuz it is different to your installation manual. I use nginx and php-fpm intead ts php for apache.

Regards

Hi all, this issue should be fixed with our latest release - https://github.com/Microsoft/msphpsql/releases/tag/4.0.4-Linux. Can you help us validate?

Yes! Great job @meet-bhagdev, I remove old ODBC Driver and install a new following your last instruction, then reinstall and copy last driver compiled version and it works perfectly with php 7.0.11 (installed from remi repo).

Awesome, in just 5 minutes I have sqlsrv driver runing on CentOS7.

CentOS Linux release 7.2.1511 (Core)
nginx version: nginx/1.11.4
PHP 7.0.11 (cli) (built: Sep 14 2016 08:28:52) ( NTS )
ExtensionVer 4.0.8909.0
Microsoft ODBC Driver 13 for SQL Server

Regards

Was this page helpful?
0 / 5 - 0 ratings