PHP IIS7 MSSQL调用未定义函数sqlsrv_connect [英] PHP IIS7 MSSQL Call to undefined function sqlsrv_connect

查看:74
本文介绍了PHP IIS7 MSSQL调用未定义函数sqlsrv_connect的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有MSSQL Server 2008,MS WINDOWS SERVER 2008 RC2和PHP 5.4

I have MSSQL Server 2008, MS WINDOWS SERVER 2008 RC2 AND PHP 5.4

php.info有行

php.info have rows

[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 SERVER我使用脚本

for connect to MSSQL SERVER i use script

$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 );

但是我看到错误:

Fatal error: Call to undefined function sqlsrv_connect() in C:\inetpub\wwwroot\89.111.180.28\index.php on line 18

请告诉我为什么我有错误以及如何做出正确的选择?

Tell me please why i have error and how make the right ?

p.s .:服务器已重新启动.

p.s.: server already was restarted.

推荐答案

您的答案肯定可以帮助我调试问题.要为其他可能已经成功安装PHP PDO SQLSRV .dll模块但仍然出现相同错误的人回答这个问题.

Your answer definitely helped me debug my problem. To add on to answer this question for others who may have successfully installed the PHP PDO SQLSRV .dll module but still get the same error.

我花了将近一个小时的时间来解决这个问题,但是即使在配置了PHP_PDO_SQLSRV之后,函数 sqlsrv_connect()仍然无法正常工作.

It took me almost an hour to figure this out, but even after I configured PHP_PDO_SQLSRV, the function sqlsrv_connect() still didn't work.

发现这是因为,如果您使用的是PDO sqlsrv扩展,则它具有自己的具有单独功能的库.

Found out it's because if you are using the PDO sqlsrv extension, it has its own library with separate functions.

要连接到数据库,您将执行以下操作:

To connect to the database, you would do something like this:

$conn = new PDO("sqlsrv:Server=localhost;Database=testdb", "UserName", "Password");

您可以在这里查看所有这些内容:

You can view all of them here:

http://msdn.microsoft.com/en-us/library/ff628159(v = sql.105).aspx

如果不确定PDO与普通SQLSRV之间的区别,请参阅此帖子:

If you are unsure of the differences between PDO and normal SQLSRV, please refer to this post:

针对的SQLSRV驱动程序与PDO驱动程序带有MS SQL Server的PHP

我之所以选择PDO,是因为我希望数据以字符串形式返回(对我而言,访问速度更快,而不是解析对象/类类型).

I chose PDO because I prefer data to be returned as strings (faster access for me instead of parsing the object/class types).

这篇关于PHP IIS7 MSSQL调用未定义函数sqlsrv_connect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆