我在 php pdo 中创建了删除语句。我需要知道我的代码的 bind_param 查询。我使用了一个不工作的 bind_param。
PHP7
public function deleteRecord($table,$pk,$id){
if($table == "categories"){
$pre_stmt = $this->con->prepare("SELECT ".$id." FROM categories WHERE parent_cat = ?");
$pre_stmt->bind_param("i",$id);
$pre_stmt->execute();
$result = $pre_stmt->get_result() or die($this->con->error);
if ($result->num_rows > 0) {
return "DEPENDENT_CATEGORY";
}else{
$pre_stmt = $this->con->prepare("DELETE FROM ".$table." WHERE ".$pk." = ?");
$pre_stmt->bind_param("i",$id);
$result = $pre_stmt->execute() or die($this->con->error);
if ($result) {
return "CATEGORY_DELETED";
}
}
蝴蝶不菲