【发布时间】:2026-02-09 20:45:02
【问题描述】:
新手问题:我是第一次将 php 连接到 SQL Server。已使用 sqlsrv_connect 函数建立连接。
我现在正在尝试返回行,但它返回此错误:
未定义索引:第 62 行 [FilePath] 中的版本
<?php
$sql = "SELECT @@VERSION AS [version]";
$stmt = sqlsrv_query( $conn, $sql);
if($stmt === false) //if the query returns no rows
{
die(print_r(sqlsrv_errors(), true));
};
//echo the opening definition of the table in HTML5
echo "<table>
<tr>
<th>Version</th>
</tr>";
//echo the rows returned
while( $row = sqlsrv_fetch_Array($stmt, SQLSRV_FETCH_ASSOC) )
{
echo "<tr>";
echo "<td>".$row['Version']."</td>" ; //<<- This is line 62
echo "</tr>";
}
//close the table tag
echo "</table>";
?>
我希望这是一个新问题,我错过了一些非常明显的东西。我不是 PHP 编码员,你可以想象。
更新:感谢这个问题与另一个问题的答案有关,但实际上,我的问题肯定是不同的,因为解决方案不同。这里的解决办法是和代码中的字符大小写有关。
【问题讨论】:
-
$row['Version']应该是$row['version']
标签: php sql-server xampp