我想学习如何在我的PHP中使用准备好的语句,从MySQL数据库中获取数据。目前我没有得到任何打印出来的东西。绑定参数MySQl和PHP
我需要有一个while循环经历我的数据库中的行。那是对的吗?
我在这里正确的方式,或我错过了什么?我在代码中做了一些评论,描述我在做什么。
<?php
$stmt = $mysqli->prepare("SELECT * FROM fantasies WHERE headline = ? AND description = ? AND place = ? ORDER BY reg_date DESC LIMIT 3");
// Execute prepared statement
if ($stmt->execute()) {
$success = true;
}
// Make variables ready
$head = null;
$desc = null;
$plac = null;
// Bind result to variables
$stmt->bind_result($head, $desc, $plac);
while ($stmt->fetch()) {
// What should go here?
echo "Headline: ".$head."Description: ".$desc."Place: ".$place;
}
// Close statement
$stmt->close();
// Close connection
$mysqli->close();
if($success) {
echo "Selected Succesfull";
} else {
echo "Failed: " . $stmt->error;
}
}
?>
使用[NUM_ROWS](http://php.net/ manual/enq/mysqli-result.num-rows.php)检查查询返回结果是否为 – Saty
您执行两次 –
感谢您的意见。我更新了我的问题 – KrMa