PHP无法连接到数据库

时间:2016-07-05 08:21:25

标签: php sql-server

我正在尝试为Android创建一个简单的Web服务(用PHP编写),它对SQL Server进行Db调用并在IIS上部署

<?php

$serverName = "MyDB/Instance"; 
$connectionInfo = array( "Database"=>"MyDB", "UID"=>"MYID", "PWD"=>"MyPWD");
$conn = sqlsrv_connect( $serverName, $connectionInfo);


$tsql = "SELECT * FROM tblEmployee";  

$stmt = sqlsrv_query( $conn, $tsql);  

if ( $stmt )  
{  
     echo "Statement executed.<br>\n";  
}   
else   
{  
     echo "Error in statement execution.\n";  

     die( print_r( "Error", true));  
}  

while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC))  
{  
     echo "Col1: ".$row[0]."\n";  
     echo "Col2: ".$row[1]."\n";  
     echo "Col3: ".$row[2]."<br>\n";  
     echo "-----------------<br>\n";  
}  

sqlsrv_free_stmt( $stmt);  
sqlsrv_close( $conn);  
?>  

................ 我的浏览器根本不支持此

enter image description here

我的港口工作正常

enter image description here

这是我在C:\ inetpub \ logs \ LogFiles \ W3SVC11上找到的错误日志

#Software: Microsoft Internet Information Services 10.0
#Version: 1.0
#Date: 2016-07-05 07:38:34
#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken
2016-07-05 07:38:34 ::1 GET / - 8092 - ::1 Mozilla/5.0+(Windows+NT+10.0)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/51.0.2704.103+Safari/537.36 - 200 0 0 31402
2016-07-05 07:38:34 ::1 GET /Content/site.css - 8092 - ::1 Mozilla/5.0+(Windows+NT+10.0)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/51.0.2704.103+Safari/537.36 http://localhost:8092/ 200 0 0 1
2016-07-05 07:38:34 ::1 GET /Scripts/modernizr-2.6.2.js - 8092 - ::1 Mozilla/5.0+(Windows+NT+10.0)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/51.0.2704.103+Safari/537.36 http://localhost:8092/ 200 0 0 104
2016-07-05 07:38:34 ::1 GET /Content/bootstrap.css - 8092 - ::1 Mozilla/5.0+(Windows+NT+10.0)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/51.0.2704.103+Safari/537.36 http://localhost:8092/ 200 0 0 117
2016-07-05 07:38:34 ::1 GET /Scripts/respond.js - 8092 - ::1 Mozilla/5.0+(Windows+NT+10.0)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/51.0.2704.103+Safari/537.36 http://localhost:8092/ 200 0 0 115
2016-07-05 07:38:34 ::1 GET /Scripts/bootstrap.js - 8092 - ::1 Mozilla/5.0+(Windows+NT+10.0)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/51.0.2704.103+Safari/537.36 http://localhost:8092/ 200 0 0 116
2016-07-05 07:38:34 ::1 GET /Scripts/jquery-1.10.2.js - 8092 - ::1 Mozilla/5.0+(Windows+NT+10.0)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/51.0.2704.103+Safari/537.36 http://localhost:8092/ 200 0 0 366
2016-07-05 07:38:36 ::1 GET /favicon.ico - 8092 - ::1 Mozilla/5.0+(Windows+NT+10.0)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/51.0.2704.103+Safari/537.36 http://localhost:8092/ 200 0 0 38
2016-07-05 07:39:01 ::1 GET /select.php - 8092 - ::1 Mozilla/5.0+(Windows+NT+10.0)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/51.0.2704.103+Safari/537.36 - 500 0 0 817
2016-07-05 07:39:52 ::1 GET /select.php - 8092 - ::1 Mozilla/5.0+(Windows+NT+10.0)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/51.0.2704.103+Safari/537.36 - 500 0 0 30
#Software: Microsoft Internet Information Services 10.0
#Version: 1.0
#Date: 2016-07-05 08:22:23
#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken
2016-07-05 08:22:23 ::1 GET / - 8092 - ::1 Mozilla/5.0+(Windows+NT+10.0)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/51.0.2704.103+Safari/537.36 - 200 0 0 4699
2016-07-05 08:22:34 ::1 GET /select.php - 8092 - ::1 Mozilla/5.0+(Windows+NT+10.0)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/51.0.2704.103+Safari/537.36 - 500 0 0 480
2016-07-05 08:25:56 ::1 GET / - 8092 - ::1 Mozilla/5.0+(Windows+NT+10.0)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/51.0.2704.103+Safari/537.36 - 200 0 0 8

我试图在另一台浏览器上运行,但它也没有响应

我无法诊断错误,里面发生了什么错误? 我发现一些文章正确连接php页面和Sql Server,我相信我的代码是对的,仍然无法找到原因,

0 个答案:

没有答案