首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IIS7对未定义函数sqlsrv_connect的MSSQL调用

问IIS7对未定义函数sqlsrv_connect的MSSQL调用
EN

Stack Overflow用户
提问于 2012-12-04 13:15:19
回答 3查看 14.8K关注 0票数 5

我有MSSQL 2008,MS WINDOWS Server 2008 RC2和PHP5.4

php.info有行

代码语言:javascript
复制
[PHP_PDO_SQLSRV_54_NTS]
extension=php_pdo_sqlsrv_54_nts.dll
[PHP_PDO_ODBC]
extension=php_pdo_odbc.dll
[PHP_SYBASE_CT]
extension=php_sybase_ct.dll
[PHP_SQLSRV_54_NTS]
extension=php_sqlsrv_54_nts.dll

Php在这里找到http://89.111.180.28/index.php

我看到了带有扩展php.ini的行,但是在php.info.中没有看到带有扩展SQLSRV的行

为了连接到MSSQL服务器,我使用脚本

代码语言:javascript
复制
$conn_array = array (
            "UID" => "user", 
            "PWD" => "passw", 
            "Database" => "database",
            "Encrypt" => 1,
            "TrustServerCertificate" => 1) ;

$conn2 = sqlsrv_connect('localhost' , $conn_array);

if ($conn2)
    {
        echo 'MSSQL Connection successful';
    }
else
    {
        die( print_r( sqlsrv_errors(), true));
    }

sqlsrv_close( $conn2 );

但我看到了错误:

代码语言:javascript
复制
Fatal error: Call to undefined function sqlsrv_connect() in C:\inetpub\wwwroot\89.111.180.28\index.php on line 18

请告诉我,为什么我有错误,如何做正确的?

服务器已经重新启动。

EN

回答 3

Stack Overflow用户

发布于 2016-01-26 03:06:27

我自己也有这个问题。我终于把它修好了,所以我想我可以分享一下。

问题是,虽然我安装了sqlsrv (复制到我的php/ext文件夹),并且在我的php.ini中添加了它,在IIS中添加了,但是它是“禁用”。

这里有一些逐步的说明,以防有人再次出现同样的问题。(或供我日后参考:)

  1. 下载(并安装) Server驱动程序 (.dll)
代码语言:javascript
复制
- Install them by running the .exe, and typing the path to your php extensions folder when it asks you where to decompress them.  
    - To find your current extension directory, run (cmd.exe) `php -i | more`, and look for the line `extension_dir`. (For me it was on the fourth press of `more`).  Alternately, make a simple php file containing only `<?php phpinfo(); ?>`, and run it in the browser.  This will give the same information, but in a much easier-to-read format.

​

​

  1. 将扩展添加到php.ini中
代码语言:javascript
复制
- To find the right php.ini, either run `php -i | more` again, looking for `Loaded Configuration File`, or check that simple php script again (I highly recommend you make it - it'll save you time and effort).  The path you find there is the file you need to edit.
- Add the following lines to your php.ini, and save it:  

[PHP_SQLSRV] extention=php_sqlsrv_56_nts.dll

​

  1. 启用IIS管理器中的扩展程序
代码语言:javascript
复制
- In the start menu, type `IIS Manager`, and press enter.
- Click on your Server's name in the left side bar
- Click `PHP Manager`
- Under `PHP Extensions`, click `Enable or Disable an Extension`.
- If your extension is not under `Enabled`, look under `Disabled` for it.  When you find it, right-click on it, and click `Enable` in the context menu that appears.

​

  1. 测试以确保其工作正常
代码语言:javascript
复制
- Open that `phpinfo()` page you made (you did, didn't you?), and look under `Registered PHP Streams`. If you see `sqlsrv` in that list, you're set!

​

票数 4
EN

Stack Overflow用户

发布于 2012-12-05 08:48:51

我明白现在的情况。

我使用的PHP版本在5.4以上,所以使用PHP驱动程序进行Windows3.0。

对于此配置,需要SQL 2012的客户端版本,但我一直是客户端SQL 2008版本。

问题解决了。

票数 0
EN

Stack Overflow用户

发布于 2020-02-28 20:15:35

如果使用sql server 2008 r2,则只需下载丢失的组件,如数据库管理器和microsoft sql server 2008R2管理对象,并继续下载直到成功为止。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13703824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档