Codeigniter / Postgresql:致命错误:在非对象上调用成员函数num_rows()

时间:2016-07-22 04:53:25

标签: php postgresql codeigniter

这件事困扰了我几天,我还没有能够解决它。我有这个登记表。提交此表单时,此错误会不断弹出,发生这种情况的原因是注册详细信息未插入数据库。

我使用Postgresql作为数据库系统。但数据没有插入。我真的很沮丧。我将在下面发布我的模型,控制器,如果有任何需要请告诉我。

控制器:

    function register()
{

    //set validation rules
    $this->form_validation->set_rules('customer_name', 'Customer Name', 'trim|required|xss_clean');
    $this->form_validation->set_rules('address1', 'Address 1', 'trim|required|xss_clean');
    $this->form_validation->set_rules('address2', 'Address 2', 'trim|required|xss_clean');
    $this->form_validation->set_rules('city', 'City', 'trim|required|xss_clean');
    $this->form_validation->set_rules('state', 'State', 'trim|required|xss_clean');
    $this->form_validation->set_rules('country', 'Country', 'trim|required|xss_clean');
    $this->form_validation->set_rules('phone', 'Phone', 'trim|required|xss_clean|is_numeric');
    $this->form_validation->set_rules('mobile', 'Mobile', 'trim|required|xss_clean|is_numeric');
    $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[gkb_users.email]');
    $this->form_validation->set_rules('username', 'Username', 'trim|required|is_unique[gkb_users.username]');
    $this->form_validation->set_rules('password', 'Password', 'trim|required|md5');
    $this->form_validation->set_rules('confpassword', 'Confirm Password', 'trim|required|matches[password]|md5');

    //validate form input
    if ($this->form_validation->run() == FALSE)
    {
    //fails
    $this->loadHeader($this);

    //load sidebar
    $this->loadSidebar($this);

    //load middle content
    $this->load->view('register_view'); 

    //load footer
    $this->loadFooter($this);
    }
    else
    {
        //insert the user registration details into database
        $data = array(
            'cust_name' => $this->input->post('customer_name'),
            'address1' => $this->input->post('address1'),
            'address2' => $this->input->post('address2'),
            'city' => $this->input->post('city'),
            'state_code' => $this->input->post('state'),
            'country_code' => $this->input->post('country'),
            'phone' => $this->input->post('phone'),
            'mobile' => $this->input->post('mobile'),
            'email' => $this->input->post('email'),
            'username' => $this->input->post('username'),
            'password' => $this->input->post('password'),
        );

        // insert form data into database
        if ($this->user_model->insertUser($data))
        {
            // send email
            if ($this->user_model->sendEmail($this->input->post('email')))
            {
                // successfully sent mail
                $this->session->set_flashdata('msg','<div class="alert alert-success text-center">You are Successfully Registered! Please confirm the mail sent to your Email-ID!!!</div>');
                redirect('user/register');
            }
            else
            {
                // error
                $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Oops! Error.  Please try again later!!!</div>');
                redirect('user/register');
            }
        }
        else
        {
            // error
            $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Oops! Error.  Please try again later!!!</div>');
            redirect('user/register');
        }
    }
}

型号:

    function insertUser($data)
{
    return $this->db->insert('users', $data);
}

如果我能解决这个问题,我将非常感激。感谢

修改

    public function checkfrontendUser($username,$passwd)
{
    $sql = "
        SELECT * FROM users
        WHERE (
                    `username` = '".$username."'
                    OR
                    `email` = '".$username."'
              )
              AND `password` = '".$passwd."'
    ";      
    $result = $this->db->query($sql);
    if ($result->num_rows() > 0)
    {
        return $result->result_array();
    }       
    return FALSE;
}

1 个答案:

答案 0 :(得分:0)

主要是这可能发生在数据库连接问题或您的查询失败。无论您是通过database.php还是$this->load->database()连接数据库。仔细检查您的Db凭证。

其次你可以检查为

if($result !== FALSE){
    if ($result->num_rows() > 0){
        return $result->result_array();
    }  
}