我使用简单的codeigniter模型函数来更新数据,我正在使用REST_Controller。 codeigniter数据库更新给出了以下错误。
<h1>A Database Error Occurred</h1>
<p>Error Number: 2014</p>
<p>Commands out of sync; you can't run this command now</p>
<p>UPDATE `user` SET `fname` = 'testuser', `lname` = 'test', `age` = '18', `email` = 'test@testmail.com', `education` = 'University', `marital_status` = 'married'
WHERE `user_id` = '2'</p>
<p>Filename: controllers/api/Users.php</p>
<p>Line Number: 218</p>
</div>
下面的是我的codeigniter功能
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH . '/libraries/REST_Controller.php';
class Users extends REST_Controller
{
/**
* Constructor
*
* @return void
*/
function __construct()
{
parent::__construct();
$this->load->model('User_model');
$this->lang->load('message', 'english');
}
public function updateuser(){
$user_id = $_POST['user_id'];
$data = array('fname'=>$_POST['fname'],
'lname'=>$_POST['lname'],
'age'=>$_POST['age'],
'email'=>$_POST['email'],
'education'=>$_POST['education'],
'marital_status'=>$_POST['marital_status']
);
$this->User_model->update($data,$user_id);
}
}
和我使用MY_Model时的第二个错误
<h1>A Database Error Occurred</h1>
<p>Error Number: 2014</p>
<p>Commands out of sync; you can't run this command now</p>
<p>SHOW COLUMNS FROM `user_preferences`</p>
<p>Filename: core/MY_Model.php</p>
<p>Line Number: 206</p>
下面是我的用户模型,这是扩展MY_Model user_id是主键
<?php
class User_model extends MY_Model
{
public $primary_key = 'user_id';
//callbacks
public $before_create = array('timestamps');
public $before_update = array('update_timestamp');
public $before_get = array('getbefore');
/**
* Create timestamps before new user created
* @param array $user
* @return array
*/
protected function timestamps($user)
{
$user['created_date'] = $user['updated_date'] = date('Y-m-d H:i:s');
return $user;
}
/**
* Update timestamp before update user details
* @param array $user
* @return array
*/
protected function update_timestamp($user)
{
$user['updated_date'] = date('Y-m-d H:i:s');
return $user;
}
/**
* Check Before get Data
* check conditions before get user data
*
*/
protected function getbefore(){
$this->db->where('is_deleted','0');
}
}
?>
有没有人对此有解决方案?提前谢谢。
答案 0 :(得分:-2)
更改方法名称更新与库方法
相同