【发布时间】:2021-05-14 11:23:03
【问题描述】:
我正在尝试连接到 sql 服务器,但收到未安装 odbc 的错误。但是在我的服务器上为 php 安装了 odbc 和 sqlsrv 扩展。我正在使用 PHP 7.4.11 和 ODBC 2.3.1。请帮助。
这是我用来连接的代码
$serverName = $serverIP; //serverName\instanceName
$connectionInfo = array( "Database"=>$db, "UID"=>$user, "PWD"=>$pwd, "CharacterSet" => "UTF-8");
$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));
}
我得到的错误信息是:
Connection could not be established.
Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -49 [code] => -49 [2] => This extension requires the Microsoft ODBC Driver for SQL Server. Access the following URL to download the ODBC Driver for SQL Server for x64: https://go.microsoft.com/fwlink/?LinkId=163712 [message] => This extension requires the Microsoft ODBC Driver for SQL Server. Access the following URL to download the ODBC Driver for SQL Server for x64: https://go.microsoft.com/fwlink/?LinkId=163712 ) )
我可以通过我的本地系统使用与 windows 上的 xampp 相同的代码连接到数据库
【问题讨论】:
-
你是想神奇地连接还是有一些代码来说明你的连接?
-
@Explisam,对不起,我忘了提。现在我已经编辑了我的问题,请检查
-
发布给你的确切错误信息。
-
@Explisam 当然。
-
错误消息明确指出,就 PHP 扩展而言,Microsoft 的“SQL Server ODBC 驱动程序”未安装在运行 PHP 应用程序的服务器上。是吗?