我正在构建一个PHP页面来从Azure SQL数据库中读取数据。看起来连接和查询都有效,但我无法显示任何返回的数据。
我在网页上得到的输出是
已建立连接。 声明已执行。 有行。
<?php
$connectionInfo = array( "Database"=>"sitrap", "UID"=>"xxxxxx@xxxxxx", "PWD"=>"xxxxxx");
$serverName = "tcp:xxxxxx.database.windows.net,1433";
$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));
}
$sql = "SELECT time, callsign FROM reports";
$stmt = sqlsrv_query($conn, $sql);
if ( $stmt )
{
echo "Statement executed.<br>\n";
}
else
{
echo "Error in statement execution.\n";
die( print_r( sqlsrv_errors(), true));
}
if ($stmt) {
$rows = sqlsrv_has_rows( $stmt );
if ($rows === true)
echo "There are rows. <br />";
else
echo "There are no rows. <br />";
}
while ($row = sqlsrv_fetch_array($stmt))
{
?>
<tr>
<td><?php echo $row["time"];?></td>
<td><?php echo $row["callsign"];?></td>
</tr>
<?php
}
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
?>
答案 0 :(得分:0)
在PHP日志文件中,我发现问题是以非字符串格式返回“time”。重新格式化时间格式时,它开始起作用。
{
echo "Col1: ".$row[0]->format('Y-m-d H:i:s')."\n";
}