php 无法调用函数 sqlsrv_connect()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24776078/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot Call function sqlsrv_connect()
提问by kya
I went through several questions and recommendation to resolve the above issue, but No luck at all.
我经历了几个问题和建议来解决上述问题,但根本没有运气。
I have the following settings:
我有以下设置:
Windows Server 2008 R2
x
ampp-win32-1.8.2-5-VC9-installer
SQLSRV30 - php driver
sqlncli - Microsoft SQL Server 2008 R2 Native Client Set Up
视窗服务器 2008 R2
x
ampp-win32-1.8.2-5-VC9-installer
SQLSRV30 - php 驱动程序
sqlncli - Microsoft SQL Server 2008 R2 本机客户端设置
I installed everything else and I have the following on the php.ini file The code below show where the php drivers are residing:
我安装了其他所有东西,我在 php.ini 文件中有以下内容 下面的代码显示了 php 驱动程序所在的位置:
; On windows:
extension_dir="C:\xampp\php\ext"
The following is under windows extensions
以下是windows扩展下
extension=php_pdo_sqlsrv_54_ts.dll
extension=php_sqlsrv_54_ts.dll
When I check the phpinfo file sqlsrv is not listed. I know this may imply that its not installed, but It is installed.
当我检查 phpinfo 文件 sqlsrv 未列出时。我知道这可能意味着它没有安装,但它已安装。
The following is the php info file:
以下是php信息文件:
I also restarted apache and the server. Am I missing something ?
我还重新启动了 apache 和服务器。我错过了什么吗?
I get the following error:
我收到以下错误:
Call to undefined function sqlsrv_connect()
调用未定义的函数 sqlsrv_connect()
This the code I am using to connect: I am connecting to another server which is hosting SQL Server 2005
这是我用来连接的代码:我正在连接到另一台托管 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));
}
回答by Isaac Gachugu
I have struggled through the process and this is what has finally worked. I am using php 5.4.16 and Apache 2.4.4 with Sql Express 2008 R2.
我在整个过程中挣扎,这就是最终奏效的方法。我在 Sql Express 2008 R2 中使用 php 5.4.16 和 Apache 2.4.4。
Download Microsoft Drivers for PHP for SQL Server from Microsoft download site
Extact the files to a local folder
- Copy php_sqlsrv_54_ts.dll and php_pdo_sqlsrv_54_ts.dll to the Ext folder (C:\wamp\bin\php\php5.4.16\ext). You can confirm the folder by checking the value of extension_dir in php.ini file stored under Apache (C:\wamp\bin\apache\Apache2.4.4\bin).
- Add extension for the two drivers by adding these lines: extension=php_sqlsrv_54_ts.dll extension=php_pdo_sqlsrv_54_ts.dll and comment out the existing lines below if not commented: ;extension=php_pdo_mssql.dll ;extension=php_mssql.dll
- Start all Wamp services
从Microsoft 下载站点下载 Microsoft Drivers for PHP for SQL Server
将文件解压到本地文件夹
- 将 php_sqlsrv_54_ts.dll 和 php_pdo_sqlsrv_54_ts.dll 复制到 Ext 文件夹 (C:\wamp\bin\php\php5.4.16\ext)。您可以通过检查存储在 Apache 下的 php.ini 文件(C:\wamp\bin\apache\Apache2.4.4\bin)中 extension_dir 的值来确认该文件夹。
- 通过添加以下行为两个驱动程序添加扩展名:extension=php_sqlsrv_54_ts.dll extension=php_pdo_sqlsrv_54_ts.dll 并注释掉下面的现有行(如果没有注释): ;extension=php_pdo_mssql.dll ;extension=php_mssql.dll
- 启动所有 Wamp 服务
回答by Sundar
Load the PHP drivers in php.ini file and restart the server.
在 php.ini 文件中加载 PHP 驱动程序并重新启动服务器。
extension=php_sqlsrv_53_ts.dll
extension=php_pdo_sqlsrv_53_ts.dll
Reference:http://technet.microsoft.com/en-us/library/cc296203(v=sql.105).aspx
参考:http : //technet.microsoft.com/en-us/library/cc296203(v=sql.105).aspx
TS denotes thread safe. find your server is thread safe or non thread safe
TS 表示线程安全。发现您的服务器是线程安全的还是非线程安全的
回答by Stefan Michev
What worked for me on windows 10 64bit and php 5.6. is the 3.2 version of the driver downloaded from here:Microsoft SQL Server driver for PHP
在 Windows 10 64 位和 php 5.6 上对我有用。是从这里下载的3.2版驱动:Microsoft SQL Server driver for PHP