18

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 the php_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!

5
  • just becdause you put a file somewhere and tell php to load it doesn't mean php can ACTUALLY load it. if the function's not defined, then you provided an invalid library (e.g. wrong version, wrong compiler) and php skips it because it's not loadable. Check the server error logs to see what happened during php startup. Commented Jun 9, 2015 at 15:38
  • Thanks! where can I check the server error logs? Commented Jun 9, 2015 at 15:49
  • it'd be defined in php.ini, wherever xamp keeps that. Commented Jun 9, 2015 at 15:49
  • This is the error that I found: PHP Startup: Unable to load dynamic library 'C:\xampp\php\ext\php_sqlsrv_56_ts.dll' - The specified module could not be found. Commented Jun 9, 2015 at 15:59
  • obviously the dll isn't there... Commented Jun 9, 2015 at 18:36

4 Answers 4

25

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

  1. Download SQLSRV32.EXE (Microsoft Drivers for PHP for SQL Server) from: http://www.microsoft.com/en-us/download/details.aspx?id=20098

  2. Choose path: C:\xampp\php\ext

enter image description here

  1. Uncomment or Append extension = php_sqlsrv_56_ts.dll in php.ini

  2. 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.

Sign up to request clarification or add additional context in comments.

4 Comments

That's exactly what I did, and I still can't get the driver to load. Any other ideas?
Please make sure the dll file is in ext folder
There is no php_sqlsrv_56_ts.dll file in ext folder.What should I do??
You should downlaod it from the Microsoft website @Zahra here
10

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:

  1. Follow Lea Tano guide to install SQLSRV 5.6 (or 5.3 or..)
  2. Download and install the OBDC Driver 11 (msodbcsql.msi)
  3. Download and install the SQL Server Native Client (sqlncli.msi file)
  4. Check if installed (if not, download and install) Visual C++ Redistributable VS2012 Update4 (vcredist_x86.exe)

Comments

2

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

Make sure to use IE when you download the Web PI to your machine.

Comments

1
  1. Download Microsoft Drivers for PHP for SQL Server Windows (Link), It'll be a zip file after downloaded open the file
  2. Extract the downloaded file in default PHP extension directory (Usually c:\php\ext , c:\xampp\php\ext)
  3. To enable the SQLSRV driver, modify php.ini by adding the following line to the extension section. your PHP version and the extension/dll version should match you can refer to the below image. changing the filename as appropriate:

extension=php_sqlsrv_80_ts.dll

  1. To enable the PDO_SQLSRV driver, the PHP Data Objects (PDO) extension must be available, either as a built-in extension or as a dynamically loaded extension.

extension=php_pdo_sqlsrv_80_ts.dll

  1. Restart the Web server.

Please read the MS document Loading the Microsoft Drivers for PHP for SQL Server For Detailed Steps and more info

NOTE: REMEMBER TO LOAD THE DRIVER VERSION CORRESPONDING TO THE PHP VERSION REFER BELOW IMAGE

MS SQL DRIVER VERSION CORRESPONDING TO THE PHP VERSION

2 Comments

While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
Sure, let me just edit the answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.