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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)