无法调用函数sqlsrv_connect()

时间:2014-07-16 08:40:09

标签: php sql-server

我经历了几个问题和建议,以解决上述问题,但没有运气。

我有以下设置:

  

Windows Server 2008 R2

     

X enter image description here AMPP-win32-1.8.2-5-VC9的安装程序

     

SQLSRV30 - php驱动程序

     

sqlncli - Microsoft SQL Server 2008 R2 Native Client设置

我安装了其他所有内容,我在php.ini文件中有以下内容 下面的代码显示了php驱动程序所在的位置:

; On windows:
extension_dir="C:\xampp\php\ext"

enter image description here 以下是Windows扩展名

extension=php_pdo_sqlsrv_54_ts.dll
extension=php_sqlsrv_54_ts.dll

enter image description here

当我检查phpinfo文件时,没有列出sqlsrv。我知道这可能意味着它没有安装,但已安装。

以下是php信息文件:

我还重启了apache和服务器。我错过了什么吗?

我收到以下错误:

  

调用未定义的函数sqlsrv_connect()

这是我用来连接的代码:我正在连接另一个托管SQL Server 2005的服务器

/Connection to SQL Server Database
    error_reporting(E_ALL);
$serverName = "172.xx.x.xxx";

$connectionInfo = array('Database'=>'Eque', "UID"=>"develop", "PWD"=>"develop");
$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));
}

3 个答案:

答案 0 :(得分:8)

我一直在努力完成整个过程,这才是最终奏效的。我使用PHP 5.4.16和Apache 2.4.4与Sql Express 2008 R2。

  1. Microsoft download site

  2. 下载适用于SQL Server的PHP的Microsoft驱动程序
  3. 将文件移至本地文件夹

  4. 将php_sqlsrv_54_ts.dll和php_pdo_sqlsrv_54_ts.dll复制到Ext文件夹(C:\ wamp \ bin \ php \ php5.4.16 \ ext)。您可以通过检查存储在Apache(C:\ wamp \ bin \ apache \ Apache2.4.4 \ bin)下的php.ini文件中的extension_dir的值来确认该文件夹。
  5. 通过添加以下行为两个驱动程序添加扩展名: 延长= php_sqlsrv_54_ts.dll extension = php_pdo_sqlsrv_54_ts.dll并注释掉下面的现有行,如果没有注释: ;延长= php_pdo_mssql.dll ;延长= php_mssql.dll
  6. 启动所有Wamp服务

答案 1 :(得分:4)

将PHP驱动程序加载到php.ini文件中,然后重新启动服务器。

extension=php_sqlsrv_53_ts.dll
extension=php_pdo_sqlsrv_53_ts.dll

<强>参考: http://technet.microsoft.com/en-us/library/cc296203(v=sql.105).aspx

TS表示线程安全。发现您的服务器是线程安全的或非线程安全的

答案 2 :(得分:0)

在Windows 10 64bit和php 5.6上对我有用。是从这里下载的3.2版驱动程序:Microsoft SQL Server driver for PHP