php 7无法初始化sqlsrv

时间:2015-10-04 21:40:34

标签: dll sqlsrv php-ini php-7

我整天都在搜索php 7 VC14 x64线程安全上的sqlsrv dll解决方案,但我没有找到解决方案。有没有人解决了这个问题:

[04-Oct-2015 19:48:05 UTC] PHP Warning:  PHP Startup: pdo_sqlsrv: Unable to initialize module
Module compiled with module API=20131226
PHP    compiled with module API=20141001
These options need to match
 in Unknown on line 0

这是我的php7 RC4信息:

System  Windows NT 6.0 build 6002 (Windows Server 2008 Standard Edition Service Pack 2) AMD64
Build Date  Sep 29 2015 17:15:28
Compiler    MSVC14 (Visual C++ 2015)
Architecture    x64

3 个答案:

答案 0 :(得分:13)

sqlsrv尚未为PHP7做好准备,但事实并非如此,自2012年以来尚未发布。最新版本发布于2015年5月.Maintainer是Microsoft,PHP7的版本计划于明年年初开始。

https://github.com/Azure/msphpsql/issues/58

<强>更新

今天(2017年3月)即使是Linux版本的驱动程序也可用于高达7.1版本的PHP。

https://github.com/Microsoft/msphpsql

答案 1 :(得分:8)

供将来参考(在Windows 7上使用Xampp和PHP 7.0.13测试):

  1. 在此处下载并安装ODBC驱动程序:https://www.microsoft.com/en-US/download/details.aspx?id=36434

  2. 在此处下载DLL(7.0和7.1都可以找到):https://github.com/Microsoft/msphpsql/releases

  3. 打开“ php.ini ”文件,然后查找“ extension_dir ”行。这将告诉您放置DDL文件的位置。 注意:在Xampp上,它应该类似于:“ C:\ xampp \ php \ ext

  4. enter image description here

    1. 将DLL文件包含在Zip存档中的扩展目录中。确保选择正确的版本。 注意:我最初尝试使用x64版本,但它无效。然后,我用x86版本替换了DLL,它终于工作了。
    2. enter image description here

      1. 返回“php.ini”文件,需要添加以下行:“ extension = php_pdo_sqlsrv_7_ts.dll ”。 注意:Xampp使用胎面安全版本。
      2. enter image description here

        1. 确保重新启动Apache服务。
        2. enter image description here

          用于测试的代码示例:

          $db = "the name of your database"
          $password = "password";
          $server = "IP address or named pipe";
          $user = "username"
          
          try {
          
              $connection = new PDO(
                  "sqlsrv:Server=" . $server . 
                      ";Database=" . $db, 
                  $password, 
                  $user
              );
          
              $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
          
          } catch (PDOException $exception) {
          
              var_dump($exception);
          }
          

答案 2 :(得分:1)

对于记录,指向sql server库的直接链接在这里

sqlsrvr for php 7

ts和nts的32位和64位版本

相关问题