3

I am trying to connect my SQL server with PHP using Xampp. I have already uploaded dll files in the ext folder but I am unable to connect it. My PHP version is 7.2.6. Uploaded dll files are - php_pdo_sqlsrv_72_ts.dll, php_sqlsrv_72_ts.dll. I have written this code to connect my SQL database with PHP-

<?php   
$serverName = "INDO-SERV\SQLEXPRESS,1443";  
$uid = "sa";     
$pwd = "XXXXXX";    
$databaseName = "web";  
$connectionInfo = array("UID" => $uid, "PWD" => $pwd, "Database"=>$databaseName);  
$conn = sqlsrv_connect( $serverName, $connectionInfo);  
if( $conn )  
{  
     echo "Connection established.\n";  
}  
else  
{  
     echo "Connection could not be established.\n";  
     die( print_r( sqlsrv_errors(), true));  
}  
sqlsrv_close( $conn);  
?>     
 
 

I am getting this error when I had tried this-

Fatal error: Uncaught Error: Call to undefined function sqlsrv_connect() in C:\xampp\htdocs\biometric\db.php:7 Stack trace: #0 {main} thrown in C:\xampp\htdocs\biometric\db.php on line 7.

Anyone has an idea where I am doing wrong or how to connect with the database.

5
  • So what is the actual error you see? What message? We cannot guess that... Commented Dec 7, 2018 at 6:11
  • And what "dll files" did you upload where and why? Commented Dec 7, 2018 at 6:11
  • I have updated the post please check it once. Commented Dec 7, 2018 at 6:15
  • @SahilVerma Your PHP Driver is not installed correctly. Run <?php phpinfo();?> and check for 'sqlsrv' section in the output. Commented Dec 7, 2018 at 7:49
  • I have already installed the driver with a matching version of PHP. My current PHP version is 7.2. Commented Dec 7, 2018 at 12:01

4 Answers 4

8

Installation of PHP Driver for SQL Server (sqlsrv and/or pdo_sqlsrv PHP extensions) can be done following the next steps:

Check the configuration with <?php phpinfo();?>. There should be a section with name pdo_sqlsrv (if you use PDO) and/or sqlsrv (without PDO).

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

Comments

3

my XAMPP version is 7.0.13

1- Download and Install "SQLSRV40.EXE" on this path:

D:\xampp\php\ext

2- Download and Install "msodbcsql.msi"

3- Edit file ":\xampp\php\php.ini" and add this extensions :

extension=php_sqlsrv_7_ts_x86.dll
extension=php_pdo_sqlsrv_7_ts_x86.dll
extension=php7ts.dll

4- restart xampp

Note: "SQLSRV40.EXE" Contain this extensions:
php_sqlsrv_7_ts_x86.dll , php_pdo_sqlsrv_7_ts_x86.dll , php7ts.dll

Comments

1

Download driver from:

https://download.microsoft.com/download/f/4/d/f4d95d48-74ae-4d72-a602-02145a5f29c8/SQLSRV510.ZIP

  • Unzip the files
  • Copy the dll files in C:\xampp\php\ext\
  • Open with your favourite editor the file php.ini located in C:\xampp\php\
  • Insert the extensions:
extension=pdo_sqlsrv_74_ts_x64 
extension=sqlsrv_74_ts_x64
  • Restart Apache and PHP

Comments

0

For the new comers;

You can setup driver and integrate it as in this video explains so in a nutshell;

  • You should find drivers for php - sql server integration depending to your environment (versions) at links and download the driver that suits for your environment.

  • You should move the driver file (.dll for windows case) to php/ext folder.

  • You need to change php.ini as entering a new extension (for example extension=php_sqlsrv_7_ts.dll) by giving your exact file name you have moved to php/ext.

  • Restart your local server and you should see this extension in phpinfo(), if you can see it's there, you can connect to your db with your credentials and it's done.

Credits goes to creator of the video (applause) :)

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
Thank you for your meaningful feedback, I changed my 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.