删除记录时 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;

这是我得到的:

A Database Error Occurred Error Number: 1054

Unknown column '108' in 'where clause' DELETE FROM tbl_post WHERE post_Id = '108' AND 108 IS NULL

Filename: C:\xampp\htdocs\socialsite\system\database\DB_driver.php

Line Number: 330

试试这个,它会有所帮助,没有必要 return 什么。

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');
}

修复了错误 在此代码中,有 2 个值传递给删除。因此,在 $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']);