我从 MySQL 数据库中获取数据时遇到问题。它获取行,并且在使用 print_r 打印结果时看起来是正确的,但是当获取数组中的一项时始终为空,我不知道为什么!
如果我使用 phpMyAdmin,我可以看到数据库中的所有行并且它们看起来是正确的。
有人有想法吗?
<?php
$con = mysqli_connect($host, $user, $password) or die("Failed to connect to MySQL: " . mysqli_connect_error());;
mysqli_select_db($con, $database) or die("Cannot select DB");
$r = mysqli_query($con, "SELECT Question FROM TempQuestions") or die('Query failed: ' . mysql_error());
Print "Rows ". mysqli_num_rows($r) . "<br>"; // Returns 10 rows
while ($dbResult = mysqli_fetch_array( $r)) {
print_r($dbResult); // Prints the question like Array ([0] => The question in DB, [Question] => The question in DB)
Print "<br><br>";
Print "Question: ";
Print $dbresult['Question']; // Is always empty!
Print $dbresult[0]; // Is always empty!
Print "<br><br>";
}
mysqli_free_result($r);
mysqli_close($con);
?>