dongmi1872 2016-06-28 07:33
浏览 285

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

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
  • 写回答

1条回答 默认 最新

  • dongsuishou8039 2016-09-14 15:14
    关注

    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

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

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100