我正在尝试编写我的第一个PHP脚本。 我要在页面中显示一些sql server表的完整内容: 因此,记录第一行的名称,然后记录每行的内容,并写一段时间谷歌写道:
<?php
header('Content-Type: text/html; charset=utf-8');
$sql="Select * from Shipments";
$serverName = "TEST";
$connectionInfo = array( "Database"=>"test", "UID"=>"sa", "PWD"=>"pwd");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
//print "Connection established.<br />";
}else{
//print "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
$result = sqlsrv_prepare( $conn, $sql );
echo "<table><tr>";
foreach( sqlsrv_field_metadata( $result ) as $field ) {
echo "<th>";
echo $field['Name'];
echo "</th>";
}
echo "</tr>\n";
//here goes rows
echo "</table>";
sqlsrv_free_stmt( $result);
?>
但这只显示标题(记录名称),然后我必须添加所有值的行,我想添加这个:
while($row = sqlsrv_fetch_array($result))
{
echo "<tr>";
foreach($row as $cell)
{
echo "<td>";
echo $cell;
echo "</td>";
}
echo "</tr>\n";
}
但不起作用: - (
可以建议解决方案
由于