php - php与sql server集成的问题

标签 php sql-server sql-server-express php-5.5

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

  • php:版本 5.5
  • SQL Server:2005 Express
  • php 驱动程序:sqlsrv 3.2
  • 线程安全:已禁用

我遇到以下错误:

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));
}
?>

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

最佳答案

适用于 PHP 的 Microsoft SQL Server 驱动程序需要安装 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

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

关于php - php与sql server集成的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30510938/

相关文章:

php - 如何重定向到移动网站,同时仍然打开选项以查看桌面版本

c# - SQL 异常 - 与网络相关或特定于实例。 SQL Express "It works on my machine"问题

sql-server - 在 SQL Server 2005 中应该使用什么数据类型来存储电话号码?

SQL Server 2008 - 当列为空时设置一个值

c# - 错误 - 具有多个数据库连接的 LINQ/TransactionScope

.net - 在 SQL 或文件系统中将文档另存为 BLOB

sql-server - SQL Server Express 数据库大小/BLOB 存储

php - 从下到上获取 PHP 变量

php - 拉维尔 5.1 : Register user and send data to two tables at the same time: Users and Users_details

php - 为什么在此代码中通过引用传递速度较慢?