php - CRUD应用程序上的错误号1054

标签 php codeigniter model error-handling

我收到此错误,有人知道这可能是什么原因吗?我认为它与模型有关,但无法弄清楚。

Error Number: 1054

Unknown column 'id' in 'order clause'

SELECT * FROM (tblquestions) ORDER BY id asc LIMIT 5

Filename: C:\wamp\www\Surva\system\database\DB_driver.php

Line Number: 330


模型
private $primary_key = 'QID';
private $table_name = 'tblquestions';

function get_paged_list($limit=10, $offset=0, $order_column='', $order_type='asc')
{
    if (empty($order_column) || empty($order_type)) {
        $this->db->order_by($this->primary_key, 'asc'); 
    }
    else {
        $this->db->order_by($order_column, $order_type);
        return $this->db->get($this->table_name, $limit, $offset);
    }
}

function count_all()
{
    return $this->db->count_all($this->table_name); 
}

function get_by_id($id)
{
    $this->db->where($this->primary_key, $id);
    return $this->db->get($this->table_name);
}

function save($question)
{
    $this->db->insert($this->table_name, $question);
    return $this->db->insert_id();  
}

function update($id,$question)
{
    $this->db->where($this->primary_key, $id);  
    $this->db->update($this->table_name, $question);
}

function delete($id)
{
    $this->db->where($this->primary_key, $id);
    $this->db->delete($this->table_name);
}

最佳答案

请将id更改为qid为:

      SELECT * FROM (tblquestions) ORDER BY qid asc LIMIT 5

您在查询中输入了错误的列名。

关于php - CRUD应用程序上的错误号1054,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15427729/

相关文章:

javascript - 在 php 表单提交之前添加电子邮件验证

php - 避免由于页面刷新而提交的最佳方法

javascript - Ember.js - 调用父模型 Hook 为子模型加载数据

javascript - 如何使用 HTML5 从文件夹中的文件创建动态播放列表

php - 如何使用 the_permalink();选择数据库查询中的wordpress?

php - CodeIgniter 中缩短的电子邮件主题

codeigniter - 如何使用CodeIgniter获得YouTube嵌入代码?

mysql - Codeigniter 查询不起作用

ruby-on-rails - 如何创建用于查找 Rails 模型记录的黑名单/白名单?

php - Laravel 5 数组, key 保存在模型中