删除记录时where子句codeigniter中的未知列


unknown column in where clause codeigniter when deleting record

我有一个简单的查询来从mysql数据库中删除记录。

这是我的问题:

$this->db->where('post_Id', $post_Id);
$result = $this->db->delete($this->mastables['post'],$post_Id);
return $result;

这就是我得到的:

发生数据库错误错误编号:1054

未知列"where clause"中的"108"DELETE FROM tbl_post where post_Id="108"和108为空

文件名:C: ''examplep''htdocs''socialsite''system''database''DB_driver.php

Line编号:330

试试这个,它会有所帮助,而且不需要返回什么。

function delete($your_id)
{
    $this->db->where('your_tb_id',$your_id); //your_tb_id is key field in your table
    $this->db->delete('table_name');
}

修复了错误在这段代码中,有两个值被传递给delete。因此,在$result中删除$post_Id将起作用。

$this->db->where('post_Id', $post_Id);
$result = $this->db->delete($this->mastables['post'],$post_Id);

更新代码:

$this->db->where('post_Id', $post_Id);
$result = $this->db->delete($this->mastables['post']);