致命错误:未捕获错误:调用 C:\xampp\htdocs\DBtest\sqlsrv.php:7 中的函数 sqlsrv_connect() 堆栈跟踪:#0 {main} SQLSERVER

问题描述

错误问题:

致命错误:未捕获的错误调用未定义的函数 C:\xampp\htdocs\DBtest\sqlsrv.PHP:7 中的 sqlsrv_connect() 堆栈跟踪: #0 {main} 在第 7 行的 C:\xampp\htdocs\DBtest\sqlsrv.PHP 中抛出

用于测试连接的 PHP

<?PHP
$serverName = "LAPTOP-NUUM4IGR\sqlEXPRESS"; //serverName\instanceName

// Since UID and PWD are not specified in the $connectionInfo array,// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>"perkuliahan");
$conn = sqlsrv_connect( $serverName,$connectionInfo);

if( $conn ) {
     echo "Connection established.<br />";
}else{
     echo "Connection Could not be established.<br />";
     die( print_r( sqlsrv_errors(),true));
}
?>

PHP.ini 文件

extension=PHP_pdo_sqlsrv_74_nts_x64.dll 
extension=PHP_pdo_sqlsrv_74_ts_x64.dll 
extension=PHP_sqlsrv_74_nts_x64.dll 
extension=PHP_pdo_sqlsrv_74_ts_x64.dll

我的 PHPinfo 上的 pdo_sqlsrv 看起来不错。扩展版本 5.8.0 + 12928 我已经安装了 ODBC PHP 版本 7.4.10

之前我用的是 sql SERVER 2008 R2,我猜这不符合条件,所以我升级sql Server 2012。但还是卡住了 我做错了吗?我非常感谢您的解决方案。

解决方法

MSSQL 扩展在使用 PHP 5.3 或更高版本的 Windows 上不再可用。 SQLSRV,Microsoft 提供了 MS SQL 的替代驱动程序:

»http://www.microsoft.com/en-us/download/details.aspx?id=20098

1.从以下位置下载 SQLSRV32.EXE(Microsoft Drivers for PHP for SQL Server):http://www.microsoft.com/en-us/download/details.aspx?id=20098

2.选择路径:C:\xampp\php\ext

3.在php.ini中取消注释或附加扩展名= php_sqlsrv_56_ts.dll

4.从 XAMPP 控制面板重启 Apache(停止/启动)

我测试了它,它 100% 有效