【发布时间】:2013-12-13 21:14:17
【问题描述】:
正在重做网站。升级到 mysqli,现在我正在用准备好的语句整理代码和安全性。我知道语句应该在 foreach 循环之外准备,但我想知道条件语句。
[code that decides $table]
foreach ($_POST[$lastvar] as $key => $value) {
[code not relevant to Q]
$sql3 = "SELECT * from $table WHERE titlesid=? and peopleid=?";
$stmt3 = $mysqli->prepare($sql3);
$stmt3->bind_param("ii", $titlesid,$peopleid);
$stmt3->execute();
if ($stmt3->num_rows == 0) {
if ($table == "dhereviewers") {
$sql = "INSERT into $table (titlesid,peopleid) VALUES (?,?)";
} else {
$sql = "INSERT into $table (titlesid,peopleid,billing) VALUES (?,?,?)";
}
$billing++;
[prepare/execute one of the last two statements]
}
}
}
因此,根据“如果”,我将执行最后两个插入中的一个或另一个。因为它们是有条件的,我是否只在它们被“选择”时才准备它们?
希望我很清楚。 :-)
仍在学习准备好的语句。
【问题讨论】:
标签: php mysqli prepared-statement