将 php 与 sqlserver 集成的问题

issue integrating php with sqlserver

这是我第一次将 php 与 SQL 服务器集成。上下文中的 SQL 服务器位于同一局域网中的另一台物理计算机上。我正在使用下面解释的配置:

我遇到以下错误:

Connection could not be established.
Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -49 [code] => -49 [2] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712 [message] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712 ) [1] => Array ( [0] => IM002 [SQLSTATE] => IM002 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified [message] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified ) ).

使用的代码如下:

<?php
$serverName = "TESTSERV\SQLEXPRESS"; //serverName\instanceName
$connectionInfo = array( "Database"=>"dbname", "UID"=>"username", "PWD"=>"password");
$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));
}
?>

任何人都可以指导我在这里需要做什么才能成功连接到数据库吗?

Microsoft SQL PHP 服务器驱动程序需要安装 Microsoft SQL Server 2012 Native Client,您可以在错误消息中阅读。仅下载扩展 dll 是不够的。您可以在官方 System Requirements (Microsoft Drivers for PHP for SQL Server).

中阅读更多内容

Versions 3.2 and 3.1 require Microsoft ODBC Driver 11 (or higher) for SQL Server. To download the Microsoft ODBC Driver 11 for PHP for SQL Server, see Microsoft ODBC Driver 11 for SQL Server.

If you are using the SQLSRV driver, sqlsrv_client_info will return information about which version of SQL Server Native Client is being used by the Microsoft Drivers for PHP for SQL Server. If you are using the PDO_SQLSRV driver, you can use PDO::getAttribute to discover the version.

https://www.microsoft.com/en-us/download/details.aspx?id=36434

下载、安装并尝试刷新您的测试页面。