简体   繁体   English

Codeigniter 库有问题

[英]Having trouble with Codeigniter library

I am working with a codeigniter library called MY_Model.php in that model there is the following function,我正在使用一个名为 MY_Model.php 的 codeigniter 库,其中 model 有以下 ZC1C425268E1C78A8

public function update($primary_value, $data, $skip_validation = FALSE)
{
    $valid = TRUE;
    if($skip_validation === FALSE)
    {
        $valid = $this->_run_validation($data);
    }

    if($valid)
    {
        $this->skip_validation = FALSE;
        return $this->db->where($this->primary_key, $primary_value)
            ->set($data)
            ->update($this->_table);
    }
    else
    {
        return FALSE;
    }
}

I then executing the function with the following code,然后我使用以下代码执行 function,

$update = array('last_logged_in', date("Y-m-d H:i:s"));
            if($this->ci->users_model->update($query[0]['user_id'], array('last_logged_in', date("Y-m-d H:i:s"))))
            {
                $this->session->set_flashdata('success', 'You have successfully been logged in');
                switch($query['user_type_id'])
                {
                    case 1:
                        redirect('/candidate/dashboard');
                        break;

                    case 2:
                        redirect('/employer/dashboard');
                        break;

                    case 3:
                        redirect('/admin/dashboard');
                        break;
                }
            }

However I am getting the following errors,但是我收到以下错误,

A Database Error Occurred发生数据库错误

Error Number: 1054错误号:1054

Unknown column '0' in 'field list' “字段列表”中的未知列“0”

UPDATE users SET 0 = 'last_logged_in', 1 = '2011-04-28 21:06:51' WHERE user_id = '2'更新users SET 0 = 'last_logged_in', 1 = '2011-04-28 21:06:51' WHERE user_id = '2'

Try changing尝试改变

array('last_logged_in', date("Y-m-d H:i:s"))

to

array('last_logged_in' => date("Y-m-d H:i:s"))

I think you need to change it to this:我认为您需要将其更改为:

            if($this->ci->users_model->update($query[0]['user_id'], array('last_logged_in' => date("Y-m-d H:i:s"))))

Note the array is now associative - you had a comma in there making it indexed.请注意,该数组现在是关联的 - 您在其中有一个逗号使其被索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM