Codeigniter 库遇到问题
我正在使用一个名为 MY_Model.php 的 codeigniter 库,该模型中有以下函数,
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;
}
}
然后我使用以下代码执行该函数,
$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;
}
}
但是我收到以下错误,
<块引用>发生数据库错误
错误号:1054
“字段列表”中存在未知列“0”
更新
用户
SET0
= 'last_logged_in',1
= '2011-04-28 21:06:51' 其中user_id
= '2'
I am working with a codeigniter library called MY_Model.php in that model there is the following function,
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,
$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
Unknown column '0' in 'field list'
UPDATE
users
SET0
=
'last_logged_in',1
= '2011-04-28
21:06:51' WHEREuser_id
= '2'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试更改
为
Try changing
to
我认为你需要将其更改为:
请注意,数组现在是关联的 - 你在那里有一个逗号使其成为索引。
I think you need to change it to this:
Note the array is now associative - you had a comma in there making it indexed.