这是我的代码:
$stmt1 = $db->prepare("SELECT wins FROM users WHERE id = ?");
$stmt2 = $db->prepare("SELECT losses FROM users WHERE id = ?");
$stmt1->bind_param("i", $_SESSION["id"]);
$stmt2->bind_param("i", $_SESSION["id"]);
$stmt1->bind_result($db_wins);
$stmt2->bind_result($db_losses);
$stmt1->execute();
$stmt2->execute();
$stmt1->fetch();
$stmt2->fetch();
// Print out user scores
echo "<p><strong>User:</strong> " . $_SESSION["username"] . "</p>\n";
echo "<p><strong>Wins:</strong> " . $db_wins . "</p>\n";
echo "<p><strong>Losses:</strong> " . $db_losses . "</p>\n";
一切都正确打印,除了损失,当它应该打印表中的值时打印 0。
注意事项:
- 它按预期在页面下方打印值,但不使用准备语句。
- 如果我在 phpMyAdmin(返回 0 的查询)或 Sequel Pro 中运行它,它会返回正确的损失值。