codeigniter生成的更新语法错误

时间:2015-10-12 06:14:50

标签: mysql sql codeigniter sql-update syntax-error

我正在使用codeigniter,并且有一个sql查询。我知道问题出在哪里,但不知道为它编写正确的查询。 我收到这样的错误,

UPDATE `fx_tasks` 
SET `timer_status` = 'On', `start_time` = 1444629730, `timer_started_by` = '46' 
WHERE `t_id` = '3438' 
ORDER BY `timer_status=On` DESC

我的codeingiter查询就像,

$this->db->set('timer_status', $action);
$this->db->set('start_time', time());
$this->db->set('timer_started_by', $this -> user);
$this->db->order_by("timer_status=On","DESC");
$this->db->where('t_id',$task)->update($this->tasks_table);

codeigniter中的正确查询是什么?

2 个答案:

答案 0 :(得分:3)

update语句没有order by子句。从您的codeigniter代码中删除它:

$this->db->set('timer_status', $action);
$this->db->set('start_time', time());
$this->db->set('timer_started_by', $this -> user);
$this->db->where('t_id',$task)->update($this->tasks_table);
// order by removed

你应该得到一个有效的更新声明:

UPDATE `fx_tasks` 
SET    `timer_status` = 'On',
       `start_time` = 1444629730,
       `timer_started_by` = '46'
WHERE  `t_id` = '3438'

答案 1 :(得分:1)

使用Codeigniter Update function

Exception in thread "main" org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException
  

date_default_timezone_set('asia/kolkata') $user = $this->user; $data = array( 'timer_status' => $action, 'start_time' => date('H:i:s'), 'timer_started_by' => $user ); $this->db->where('t_id', $task); $this->db->update('fx_tasks', $data); 返回当前时间并提供时区。如果您需要使用date('H:i:s')

打印时间戳
相关问题