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.

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

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏