通过 PHP 连接到映射的 SQL 服务器
connect to a mapped SQL server through PHP
我正在使用 2008 Server R2 平台上已构建的数据库,我想创建一个应用程序来查询所述数据库。
我所有的经验都是本地安装 MySQL,但是这个数据库是 MS SQL 服务器 10.50。
我的问题是,
SQL 服务器是一个映射到网络服务器的驱动器,我已经安装了所有正确的 PHP 驱动程序和 SQLsrv 扩展,并且正在获取正确的 phpinfo 读出,一切正常,但我对如何连接到 SQL 服务器感到困惑。澄清一下,
我的应用程序位于网络服务器上,我想通过 php 连接到映射到网络服务器的 SQL 服务器。我正在使用 windows 身份验证。
到目前为止我写的连接PHP看起来像这样
<?php
$serverName = "SmartCM.IMG";
$connectionInfo = array( "Database"=>"SMARTCM");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "I tried, but it didn't work out... sorry.<br /><br><br><br>";
die( print_r( sqlsrv_errors(), true));
}
?>
这是我读出的错误
Array (
[0] => Array (
[0] => 08001
[SQLSTATE] => 08001
[1] => 53
[code] => 53
[2] => [Microsoft][ODBC Driver 11 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [53].
[message] => [Microsoft][ODBC Driver 11 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [53]. )
[1] => Array (
[0] => HYT00
[SQLSTATE] => HYT00
[1] => 0
[code] => 0
[2] => [Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired
[message] => [Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired )
[2] => Array (
[0] => 08001
[SQLSTATE] => 08001
[1] => 53
[code] => 53
[2] => [Microsoft][ODBC Driver 11 for SQL Server]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][ODBC Driver 11 for SQL Server]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. )
)
Named Pipes Provider: Could not open a connection to SQL Server
您需要启用命名管道:
打开 SQL 配置管理器 -> SQL 服务器网络配置 -> 协议 -> 命名管道 -> 右键单击 -> 重新启动
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.
使用正确的服务器和实例名称(您需要确定两者),例如 PC\SQLEXPRESS
。
同时检查 TCP/IP 连接是否启用:
打开 SQL 配置管理器 -> SQL 服务器网络配置 -> 协议 -> TCP/IP -> 右键单击 -> 重新启动
检查防火墙是否阻止端口 1433 上的连接。
我正在使用 2008 Server R2 平台上已构建的数据库,我想创建一个应用程序来查询所述数据库。
我所有的经验都是本地安装 MySQL,但是这个数据库是 MS SQL 服务器 10.50。
我的问题是, SQL 服务器是一个映射到网络服务器的驱动器,我已经安装了所有正确的 PHP 驱动程序和 SQLsrv 扩展,并且正在获取正确的 phpinfo 读出,一切正常,但我对如何连接到 SQL 服务器感到困惑。澄清一下,
我的应用程序位于网络服务器上,我想通过 php 连接到映射到网络服务器的 SQL 服务器。我正在使用 windows 身份验证。
到目前为止我写的连接PHP看起来像这样
<?php
$serverName = "SmartCM.IMG";
$connectionInfo = array( "Database"=>"SMARTCM");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "I tried, but it didn't work out... sorry.<br /><br><br><br>";
die( print_r( sqlsrv_errors(), true));
}
?>
这是我读出的错误
Array (
[0] => Array (
[0] => 08001
[SQLSTATE] => 08001
[1] => 53
[code] => 53
[2] => [Microsoft][ODBC Driver 11 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [53].
[message] => [Microsoft][ODBC Driver 11 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [53]. )
[1] => Array (
[0] => HYT00
[SQLSTATE] => HYT00
[1] => 0
[code] => 0
[2] => [Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired
[message] => [Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired )
[2] => Array (
[0] => 08001
[SQLSTATE] => 08001
[1] => 53
[code] => 53
[2] => [Microsoft][ODBC Driver 11 for SQL Server]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][ODBC Driver 11 for SQL Server]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. )
)
Named Pipes Provider: Could not open a connection to SQL Server
您需要启用命名管道:
打开 SQL 配置管理器 -> SQL 服务器网络配置 -> 协议 -> 命名管道 -> 右键单击 -> 重新启动
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.
使用正确的服务器和实例名称(您需要确定两者),例如 PC\SQLEXPRESS
。
同时检查 TCP/IP 连接是否启用:
打开 SQL 配置管理器 -> SQL 服务器网络配置 -> 协议 -> TCP/IP -> 右键单击 -> 重新启动
检查防火墙是否阻止端口 1433 上的连接。