简体   繁体   中英

Failed to load SQLSRV driver on Centos 7.2 using PHP 7.0.7

I just installed a new VM in Azure with Centos 7.2. On this server I installed httpd using yum install httpd

After that I installed PHP 7.0.7 using the following link: https://webtatic.com/packages/php70/

PHP is working fine with no problem at this point.

But then I want to connect to a Azure SQL Database. After searching the forums of stackoverflow I saw that I need a PHP 7 SQLSRV driver.

I got the driver from this link: https://github.com/Azure/msphpsql/tree/PHP-7.0-Linux/CentOS7

To load the driver I copied the file to the following path: /usr/lib64/php/modules/

And updated the php.ini with the following line extension=/usr/lib64/php/modules/php_sqlsrv_7_ts.so

I did this because I was not sure if the driver is automatically loaded when placed in the modules folder. Does it load automatically?

After that I created a test.php file with the following code.

error_reporting(E_ALL);
ini_set('display_errors', 1); 

echo php_ini_loaded_file(); 
$connectionInfo = array("pwd" => "PASSWORD", $serverName = "tcp:SERVER_URL:1443"); 
$conn = sqlsrv_connect($serverName, $connectionInfo);

if( $conn ) {
     echo "Connection established.<br />"; } 
else {
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true)); 
}

The code above gives me the following error:

/etc/php.ini 
Fatal error: Uncaught Error: Call to undefined function sqlsrv_connect() in /var/www/website/test.php:9 Stack trace: #0 {main} thrown in /var/www/website/test.php on line 9

Does the PHP SQLSRV driver file needs to be written down in the phpinfo? Because I don't see it there.

Could someone help me out? If you need more information please ask and I will provide it.

Thanks in advance.

UPDATE 1:

When I run php -v on the server i get the following error:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/php_sqlsrv_7_ts.so' - /usr/lib64/php/modules/php_sqlsrv_7_ts.so: undefined symbol: SQLGetDiagField in Unknown on line 0 PHP 7.0.7 (cli) (built: May 28 2016 07:53:22) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

Have you installed unixODBC and the Microsoft ODBC Driver? You should start for there before copying the PHP extensions.

To asure you have correctly installed the unixODBC Driver Manager you could execute:

odbcinst -j

And to assure the second one you could execute:

odbcinst -q -d -n

and look for "ODBC Driver 13 for SQL Server".

Here is an extensive guide to all the necesaries step's for connecting to a SQL Database from PHP -> MS PHP SQL Linux Tutorial

PD: NO, the PHP extensions doesn't load automatically, you have to "call" them from a php.ini in the extension=extension.so form.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM