未定义索引:行 [LineNumber] 上 [Path] 中的版本
Undefined index: Version in [Path] on line [LineNumber]
新手问题:我是第一次连接 php 到 SQL 服务器。已使用 sqlsrv_connect 函数建立连接。
我现在正在尝试 return 行,但是 return 出现了这个错误:
未定义索引:第 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 编码员,正如你可能想象的那样。
更新:感谢这个问题与另一个问题的答案相关,但实际上,我的问题肯定是不同的,因为解决方案是不同的。这里的解决方案与代码中字符的大小写有关。
说真的!好的,感谢 Nick,他在评论中正确地指出我的列名称需要小写。吹爆我的新手!
$row['Version']
应该是
$row['version']
新手问题:我是第一次连接 php 到 SQL 服务器。已使用 sqlsrv_connect 函数建立连接。
我现在正在尝试 return 行,但是 return 出现了这个错误:
未定义索引:第 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 编码员,正如你可能想象的那样。
更新:感谢这个问题与另一个问题的答案相关,但实际上,我的问题肯定是不同的,因为解决方案是不同的。这里的解决方案与代码中字符的大小写有关。
说真的!好的,感谢 Nick,他在评论中正确地指出我的列名称需要小写。吹爆我的新手!
$row['Version']
应该是
$row['version']