问题
I am using
- Xampp version 3.2.1 with PHP version 5.6.8.
- Microsoft Azure SQL server
GOAL
I am trying to create a web app that will access to my database, and be able to SELECT, INSERT, UPDATE and DELETE records.
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
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.
Any help would be much appreciated!
回答1:
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
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

Uncomment or Append
extension = php_sqlsrv_56_ts.dll
inphp.ini
Restart Apache from XAMPP Control Panel (Stop/Start)
I tested it and it works 100%
You can find the most recent compiled binaries in the official Microsoft Git repository.
回答2:
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).
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)
回答3:
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
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.
http://blogs.msdn.com/b/sqlphp/archive/2015/05/11/getting-started-with-php-and-microsoft-sql-server.aspx
Best,
Meet Bhagdev
Program Manager, Microsoft
来源:https://stackoverflow.com/questions/30736601/fatal-error-call-to-undefined-function-sqlsrv-connect-in-c-xampp-htdocs