我在 php pdo 中创建了删除语句。我需要知道我的代码的 bind_param 查询。我使用了一个不工作的 bind_param。PHP7public 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"; } }
1 回答
蝴蝶不菲
TA贡献1810条经验 获得超4个赞
我纠正了上面的问题,并在下面的公共函数 getAllRecord($table){
$result = $this->con->prepare("SELECT * FROM ".$table);
$result->execute();
$results = $result->fetchAll();
$rows = array();
if ($results->rowCount > 0) {
while($row = $results->fetch(PDO::FETCH_ASSOC)){
$rows[] = $row;
}
return $rows;
}
return "NO_DATA";
}
错误:注意:试图在第 68 行的 C:\xampp\htdocs\inv_project\public_html\includes\DBOperation.php 中获取非对象的属性
- 1 回答
- 0 关注
- 129 浏览
添加回答
举报
0/150
提交
取消