调用未定义函数sqlsrv_connect()-故障排除 [英] Call to undefined function sqlsrv_connect() - Troubleshooting

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

问题描述

系统信息

CMS:Wordpress

CMS: Wordpress

Web服务器:XAMPP

Web Server: XAMPP

PHP版本:5.5.30

PHP Version: 5.5.30

MS Management Studio 17

MS Management Studio 17

目标

使用PHP建立MSSQL数据库连接

Establish MSSQL Database connection using PHP

已完成的操作


  1. 已下载的SQLSRV驱动程序

  2. 已复制的文件 php_pdo_sqlsrv_55_nts.dll php_pdo_sqlsrv_55_ts.dll 到目录 C:\xampp\php\ext

  3. 将以下行添加到php.ini文件中的动态扩展部分: extension = php_pdo_sqlsrv_55_ts.dll extension = php_pdo_sqlsrv_55_nts .dll

  4. 重启Web服务器

  5. 已确认的sqlsrv列在phpinfo()中

  1. Downloaded SQLSRV Drivers
  2. Copied files php_pdo_sqlsrv_55_nts.dll and php_pdo_sqlsrv_55_ts.dll to the directory C:\xampp\php\ext
  3. Added the following lines to the dynamic extensions part in the php.ini file: extension=php_pdo_sqlsrv_55_ts.dll and extension=php_pdo_sqlsrv_55_nts.dll
  4. Restarted Web Server
  5. Confirmed sqlsrv is listed in phpinfo()

代码

$serverName = "technology-pc\sqlexpress";

// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>"example_db");
$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));
}

错误


调用未定义函数sqlsrv_connect()

Call to undefined function sqlsrv_connect()


推荐答案

您已将SQLSRV驱动程序的PDO变体添加到扩展列表中,但尚未添加基本驱动程序 php_sqlsrv_55_ts.dll

You have added the PDO variant of SQLSRV drivers to the extension list, but have not added the base drivers php_sqlsrv_55_ts.dll.

添加到php.ini中:

Add to the php.ini:

extension=php_sqlsrv_55_ts.dll

extension=php_sqlsrv_55_nts.dll






此外,您确实应该使用驱动程序的线程安全( _ts.dll )或非线程安全( _nts.dll )版本, 不是都。我相信,当您使用Apache服务器时,应该使用线程安全版本。因此,您的php.ini应该具有:


Also, you really should be using either the Thread-Safe (_ts.dll) or Non-Thread-Safe (_nts.dll) versions of the driver, not both. I believe that, as you are using an Apache Server, you should be using the Thread-Safe versions. So you php.ini should have:

extension=php_sqlsrv_55_ts.dll
extension=php_pdo_sqlsrv_55_ts.dll

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

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