duanci9305 2016-06-01 15:25
浏览 72
已采纳

通过PHP连接到映射的SQL服务器

I am working with an already built database on 2008 Server R2 platform, and am wanting to create an application to query said DB.

All of my experience is with local installs of MySQL, however this database is an MS SQL server 10.50.

My question is this, The SQL server is a mapped drive to the web server, I've got all proper PHP drivers and SQLsrv extensions installed and am getting proper phpinfo read outs, everything is functioning properly, but I am stumped as to how to connect to the SQL server. To clarify,

My application lives on the web server, I am wanting to connect via php to the SQL server which is mapped to the web server. I'm using windows authentication.

The connection PHP i have written so far looks like this

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

This is the error read out I get

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. ) 
    )
  • 写回答

1条回答 默认 最新

  • dqzg62440 2016-06-02 11:08
    关注

    Named Pipes Provider: Could not open a connection to SQL Server

    You need to enable Named Pipes:

    Open SQL Configuration Manager -> SQL Server Network Configuration -> Protocols -> Named Pipes -> Right-click -> Restart

    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.

    Use proper server and instance names (you need to determine both) for example PC\SQLEXPRESS.

    Also check if TCP/IP connection is enabled:

    Open SQL Configuration Manager -> SQL Server Network Configuration -> Protocols -> TCP/IP -> Right-click -> Restart

    Check if firewall is blocking a connection on port 1433.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决