简体   繁体   English

无法使用PHP 7.0.7在Centos 7.2上加载SQLSRV驱动程序

[英]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. 我刚刚使用Centos 7.2在Azure中安装了新的VM。 On this server I installed httpd using yum install httpd 在此服务器上,我使用yum install httpd

After that I installed PHP 7.0.7 using the following link: https://webtatic.com/packages/php70/ 之后,我使用以下链接安装了PHP 7.0.7: https//webtatic.com/packages/php70/

PHP is working fine with no problem at this point. PHP现在可以正常工作了,没有问题。

But then I want to connect to a Azure SQL Database. 但是然后我想连接到Azure SQL数据库。 After searching the forums of stackoverflow I saw that I need a PHP 7 SQLSRV driver. 在搜索stackoverflow的论坛后,我看到我需要一个PHP 7 SQLSRV驱动程序。

I got the driver from this link: https://github.com/Azure/msphpsql/tree/PHP-7.0-Linux/CentOS7 我从此链接获得了驱动程序: 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/ 要加载驱动程序,我将文件复制到以下路径: /usr/lib64/php/modules/

And updated the php.ini with the following line extension=/usr/lib64/php/modules/php_sqlsrv_7_ts.so 并使用以下行extension=/usr/lib64/php/modules/php_sqlsrv_7_ts.so更新了php.ini 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. 我这样做是因为不确定将驱动程序放在modules文件夹中时是否自动加载驱动程序。 Does it load automatically? 它会自动加载吗?

After that I created a test.php file with the following code. 之后,我使用以下代码创建了一个test.php文件。

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? 是否需要在phpinfo中记录PHP SQLSRV驱动程序文件? 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: 更新1:

When I run php -v on the server i get the following error: 当我在服务器上运行php -v时,出现以下错误:

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? 您是否已安装unixODBC和Microsoft ODBC驱动程序? You should start for there before copying the PHP extensions. 复制PHP扩展之前,应该先从那里开始。

To asure you have correctly installed the unixODBC Driver Manager you could execute: 为确保正确安装了unixODBC Driver Manager,可以执行以下命令:

odbcinst -j odbcinst -j

And to assure the second one you could execute: 为了确保第二个可以执行:

odbcinst -q -d -n odbcinst -q -d -n

and look for "ODBC Driver 13 for SQL Server". 并查找“用于SQL Server的ODBC驱动程序13”。

Here is an extensive guide to all the necesaries step's for connecting to a SQL Database from PHP -> MS PHP SQL Linux Tutorial 这是从PHP连接到SQL数据库的所有必要步骤的详尽指南-> MS PHP SQL Linux教程

PD: NO, the PHP extensions doesn't load automatically, you have to "call" them from a php.ini in the extension=extension.so form. PD:不,PHP扩展不会自动加载,您必须从php.ini中以extension = extension.so形式“调用”它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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