以下代码应该从表中检索所有记录并将它们返回到数组。它确实返回正确数量的记录,但是所有记录都是相同的。有谁知道问题是什么?
function list_book() {
$username = "user";
$password = "pwd";
$conn = mysqli_connect('localhost', $username, $password, 'db') or die('Could Not Connect' . mysql_error());
$stmt = $conn->stmt_init();
if ($stmt->prepare("SELECT * FROM book")) {
$stmt->bind_result($r['book_id'], $r['book_title']);
if (!$stmt->execute()) {
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
exit();
}
while($stmt->fetch()){
$book[] = $r;
}
print_r($book); //**** added purposely to examine the content of the array
exit();
return $book;
}
mysqli_close($conn);
}