【问题标题】:Zero (0 ) Database Result in CodeigniterCodeigniter 中的零 (0) 数据库结果
【发布时间】:2014-05-25 18:13:40
【问题描述】:

在视图中->new_entry.php

 <?=form_open(base_url().'home/insert_entry/')?>
    <p>Title: <?=form_input('title')?></p>
    <p>Content: <?=form_textarea('content')?></p>
    <p>Tags: <?=form_input('tags')?> (comma separated)</p>
    <?=form_submit('submit', 'Insert')?>

在 home/insert_entry 中:

public function insert_entry(){
        login_site();
        $entry = array(
            'permalink'  => permalink($this->input->post('title')),
            'author' => $this->session->userdata('username'),
            'title' => $this->input->post('title'),
            'content' => $this->input->post('content'),
            'date' => date('Y-m-d H:i:s'),
            'tags' => $this->input->post('tags')
            );      
        $this->home_model->insert('ads', $entry);

        redirect(base_url());
    }

在 home_model 中:

public function insert($table, $data){
        return $this->db->insert($table, $data);
    }

我在数据库中得到所有结果为零 (0)。

【问题讨论】:

    标签: mysql database codeigniter


    【解决方案1】:

    尝试检查 affected_rows 是否 >= 1

    public function insert($table, $data){
      $this->db->insert($table, $data);
      return $this->db->affected_rows() >= 1 ? TRUE : FALSE;
    }
    

    【讨论】:

      【解决方案2】:

      在您的控制器中启用分析器。 例如:

      $this->output->enable_profiler(TRUE); 
      

      查看您的查询是否已执行,是否正确...

      【讨论】:

        猜你喜欢
        • 2015-04-08
        • 1970-01-01
        • 1970-01-01
        • 2013-09-03
        • 1970-01-01
        • 2013-05-18
        • 2021-07-24
        • 1970-01-01
        • 2015-02-26
        相关资源
        最近更新 更多