在modelSlikeVrijednost
我參考了model
-s主鍵。 ModelSlikeVrijednost
可以包含很多圖片(取決於用戶)。我需要刪除基於modelID
的文件夾。PHP MySQL準備好的語句中的語句
路徑示例:/home/mainSite/public_html/site/img/1/1/
。
可以做到這一點嗎?
代碼:
if ($stmt = $mysqli->prepare("SELECT modelID FROM model WHERE proizvodacID='$id'")) {
$stmt->execute();
$stmt->bind_result($modelID);
while ($stmt->fetch()) {
$path="/home/mainSite/public_html/site/img/".$id."/".$modelID."/";
if ($stmt1 = $mysqli->prepare("SELECT modelSlikeVrijednost FROM modelSlike WHERE modelID='$modelID'")) {
$stmt1->execute();
$stmt1->bind_result($slike);
while ($stmt1->fetch()) {
if(is_null($slike)){
rmdir($path);
}
else{
$slikePath="/home/mainSite/public_html/site/".$slike;
if($slikePath!=$path){
unlink($slikePath);
}
rmdir($path);
}
}
$stmt1->close();
}
else {
printf("Prepared Statement Error: %s\n", $mysqli->error);
}
}
$stmt->close();
}
我得到這個錯誤:Prepared Statement Error: Commands out of sync; you can't run this command now Prepared Statement Error: Commands out of sync; you can't run this command now
你應該在準備好的語句中綁定你的變量。 – jeroen 2013-02-20 14:12:50
sql結果通常會返回爲數組對象,而不是字符串。嘗試回顯$ modelID並在嘗試在另一個語句中使用它之前查看顯示內容。 – 2013-02-20 14:13:21
@JeffHawthorne:不是在使用將mysqli :: bind_result'直接綁定到PHP變量的值時。 – prodigitalson 2013-02-20 14:39:26