How to connect sql server with php using xampp?

不打扰是莪最后的温柔 提交于 2020-01-09 05:38:06

问题


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.


回答1:


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

  • Based on Microsoft PHP Drivers for SQL Server Support Matrix download appropriate version of this driver. In your case - version 5.2 or 5.3 (32-bit or 64-bit also depends on PHP version).
  • Download and install an appropriate ODBC driver - see System Requirements for the Microsoft Drivers for PHP for SQL Server
  • Load PHP Driver for SQL Server as PHP extension.
  • Restart Apache

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




回答2:


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



来源:https://stackoverflow.com/questions/53664188/how-to-connect-sql-server-with-php-using-xampp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!