零(0)Codeigniter中的数据库结果 [英] Zero (0 ) Database Result in Codeigniter

查看:113
本文介绍了零(0)Codeigniter中的数据库结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

in view-> new_entry.php

In view->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:

In 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中:

In home_model:

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

我在数据库上得到所有结果零

I am getting all result zero (0) on database.

推荐答案

尝试检查 affected_rows p>

Try checking the affected_rows if it is >= 1

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

这篇关于零(0)Codeigniter中的数据库结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆