Sahil Verma
Sahil Verma

Reputation: 53

How to connect sql server with php using xampp?

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.

Upvotes: 3

Views: 43917

Answers (4)

ycbandiran
ycbandiran

Reputation: 31

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) :)

Upvotes: 0

c c
c c

Reputation: 11

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

Upvotes: 1

Zhorov
Zhorov

Reputation: 29943

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

Upvotes: 7

Sajad Mirzaei
Sajad Mirzaei

Reputation: 2873

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

Upvotes: 3

Related Questions