php 致命错误:调用 C:\xampp\htdocs 中未定义的函数 sqlsrv_connect()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30736601/
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
Fatal error: Call to undefined function sqlsrv_connect() in C:\xampp\htdocs
提问by Robert Farb
I am using
我在用
- Xampp version 3.2.1 with PHP version 5.6.8.
- Microsoft Azure SQL server
- Xampp 3.2.1 版和 PHP 5.6.8 版。
- 微软 Azure SQL 服务器
GOAL
目标
I am trying to create a web app that will access to my database, and be able to SELECT, INSERT, UPDATEand DELETErecords.
我正在尝试创建一个可以访问我的数据库并能够SELECT、INSERT、UPDATE和DELETE记录的网络应用程序。
PROBLEM
问题
I cannot connect to the database server
我无法连接到数据库服务器
ERROR
错误
Fatal error: Call to undefined function sqlsrv_connect() in C:\xampp\htdocs\BLT\Employee_Database .php on line 25
致命错误:在第 25 行调用 C:\xampp\htdocs\BLT\Employee_Database .php 中未定义的函数 sqlsrv_connect()
CODE
代码
<html>
<head>
<Title>Employee Database</Title>
</head>
<body>
<form method="post" action="?action=add" enctype="multipart/form-data">
Last name <input type="text" name="LastName" id="LastName"/></br>
First name <input type="text" name="FirstName" id="FirstNamne"/></br>
E-mail address <input type="text" name="Email" id="Email"/></br>
User Id <input type="text" name="UserId" id="UserId"/></br>
Password <input type="password" name="Password" id="Password"/></br>
<input type="submit" name="submit" value="Submit"/>
</form>
<?php
$serverName = "jy4nij6vuy.database.windows.net,1433";
$connectionOptions = array("Database" => "robertfarb",
"UID" => "robertFarb",
"PWD" => "******");
$conn = sqlsrv_connect($serverName, $connectionOptions);
if ($conn === false) {
die(print_r(sqlsrv_errors(), true));
}
?>
</body>
</html>
THIS IS WHAT I TRIED SO FAR
这就是我到目前为止所尝试的
- I have installed the Microsoft PHP for SQL drivers and followed all the instructions to load the driver, but it does not seem to be working!
- I added the
php_sqlsrv_56.ts.dll
file to the extensions folder of PHP, and also thephp_pdo_sqlsrv_56.ts.dll
. - I also added the
extension=php_sqlsrv_56.ts.dll
line to the php.ini file.
- 我已经安装了 Microsoft PHP for SQL 驱动程序并按照所有说明加载驱动程序,但它似乎不起作用!
- 我将该
php_sqlsrv_56.ts.dll
文件添加到 PHP 的扩展文件夹中,并将php_pdo_sqlsrv_56.ts.dll
. - 我还将该
extension=php_sqlsrv_56.ts.dll
行添加到 php.ini 文件中。
Any help would be much appreciated!
任何帮助将非常感激!
回答by Leandro Papasidero
The MSSQL extension is not available anymore on Windows with?PHP 5.3 or later. SQLSRV, an alternative driver for MS SQL is available from Microsoft: ? http://www.microsoft.com/en-us/download/details.aspx?id=20098
MSSQL 扩展在 Windows 上不再可用?PHP 5.3 或更高版本。SQLSRV,Microsoft 提供的 MS SQL 替代驱动程序: ? http://www.microsoft.com/en-us/download/details.aspx?id=20098
Step by Step
一步步
Download SQLSRV32.EXE (Microsoft Drivers for PHP for SQL Server) from: http://www.microsoft.com/en-us/download/details.aspx?id=20098
Choose path: C:\xampp\php\ext
从以下位置下载 SQLSRV32.EXE(Microsoft Drivers for PHP for SQL Server):http: //www.microsoft.com/en-us/download/details.aspx?id=20098
选择路径:C:\xampp\php\ext
Uncomment or Append
extension = php_sqlsrv_56_ts.dll
inphp.ini
Restart Apache from XAMPP Control Panel (Stop/Start)
取消注释或附加
extension = php_sqlsrv_56_ts.dll
在php.ini
从 XAMPP 控制面板重新启动 Apache(停止/启动)
I tested it and it works 100%
我测试了它,它工作 100%
You can find the most recent compiled binaries in the official Microsoft Git repository.
您可以在官方 Microsoft Git 存储库中找到最新编译的二进制文件。
回答by Jordi
I followed Lea Tano guide and didn't work. I needed a fer more steps. At least for Windows7 (or for my system) there're some missing steps(ie those who don't have MSSQL Server installed in the same server/machine).
我遵循了 Lea Tano 指南,但没有奏效。我需要更多的步骤。至少对于 Windows7(或我的系统)有一些缺失的步骤(即那些没有在同一台服务器/机器上安装 MSSQL Server 的步骤)。
Here's how i made it work:
这是我如何使它工作:
- Follow Lea Tano guide to install SQLSRV 5.6 (or 5.3 or..)
- Download and install the OBDC Driver 11(msodbcsql.msi)
- Download and install the SQL Server Native Client(sqlncli.msi file)
- Check if installed (if not, download and install) Visual C++ Redistributable VS2012 Update4(vcredist_x86.exe)
- 按照 Lea Tano 指南安装 SQLSRV 5.6(或 5.3 或..)
- 下载并安装OBDC 驱动程序 11(msodbcsql.msi)
- 下载并安装SQL Server Native Client(sqlncli.msi 文件)
- 检查是否已安装(如果没有,请下载并安装)Visual C++ Redistributable VS2012 Update4(vcredist_x86.exe)
回答by meet-bhagdev
Lea's answer should do the trick for you. It is very important that you download PHP 5.6 from the Web PI - https://www.microsoft.com/web/downloads/platform.aspx
Lea 的回答应该可以为您解决问题。从 Web PI 下载 PHP 5.6 非常重要 - https://www.microsoft.com/web/downloads/platform.aspx
Use IE when you download the Web PI to your machine. Let me know if that does the trick for you, if not please have a look at the following blog. It is a getting started guide for Azure SQL DB + PHP + IIS.
当您将 Web PI 下载到您的机器时,请使用 IE。如果这对您有用,请告诉我,如果没有,请查看以下博客。它是 Azure SQL DB + PHP + IIS 的入门指南。
Best,
Meet Bhagdev
Program Manager, Microsoft
Best,
认识 Bhagdev
项目经理,微软