【问题标题】:unknown column in where clause codeigniter when deleting record删除记录时where子句codeigniter中的未知列
【发布时间】:2015-02-13 09:28:13
【问题描述】:

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

这是我的查询:

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

return $result;

这就是我得到的:

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

未知列 'where 子句'中的'108' DELETE FROM tbl_post WHERE post_Id = '108' AND 108 为空

文件名: C:\xampp\htdocs\socialsite\system\database\DB_driver.php

线 数量:330

【问题讨论】:

  • 这是什么$this->mastables['post'] 我认为应该链接这个$this->db->delete('post',$post_Id);,你为什么要返回删除?
  • 我正在使用 db config 从表名中删除前缀...stackoverflow.com/questions/4508590/what-is-a-table-prefix
  • 不明白什么意思
  • 例如:带有前缀 tbl_post 的表名,我将其用作帖子。这就是我使用“mastables ['post']”所做的。顺便说一句,您必须在 config 文件夹中有 db config php 以指向带有前缀的表名。
  • 仍然不应该在删除时使用返回。

标签: php codeigniter


【解决方案1】:

试试这个,会有帮助的,不需要退货。

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

【讨论】:

  • 我把我的代码改成了这个。这就是我得到的“不允许删除,除非它们包含“where”或“like”子句”
【解决方案2】:

修复了错误 在此代码中,有 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']);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多