【发布时间】:2014-06-12 09:00:30
【问题描述】:
我在将 Windows Apache 连接到 SQL Server Express 2008 时遇到问题
PHP 版本 5.2.9
Apache 版本 Apache/2.2.11 (Win32)
<?php
$serverName = "serverName\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));
}
?>
我尝试使用 mssql 和 sqlsrv 驱动程序,但我无法连接到数据库。这些驱动程序已正确启用。
我可以连接 sqlcmd 应用程序并成功执行查询:
sqlcmd -S serverName\SQLEXPRESS-U userName-P password
当我尝试连接 mssql 驱动程序时:
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: serverName\SQLEXPRESS in C:\xampp\htdocs\ci\demo.php on line 12
Couldn’t connect to SQL Server on $myServer
When i try to connect with sqlsrv driver:
Connection could not be established.
Array ( [0] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => -1 [code] => -1 [2] => [Microsoft][SQL Server Native Client 10.0]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF]. [message] => [Microsoft][SQL Server Native Client 10.0]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF]. ) [1] => Array ( [0] => HYT00 [SQLSTATE] => HYT00 [1] => 0 [code] => 0 [2] => [Microsoft][SQL Server Native Client 10.0]Login timeout expired [message] => [Microsoft][SQL Server Native Client 10.0]Login timeout expired ) [2] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => -1 [code] => -1 [2] => [Microsoft][SQL Server Native Client 10.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. [message] => [Microsoft][SQL Server Native Client 10.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. ) )
【问题讨论】:
标签: php sql-server apache sql-server-2008