这是我的代码:
public function remove_employee( $emp_no, $now ) {
$this->db->delete('employees', array('emp_no' => $emp_no));
$this->db->flush_cache();
$this->db->start_cache();
$this->db->where('emp_no', $emp_no);
$this->db->where('to_date', '9999-01-01');
$this->db->update('dept_emp', array('to_date' => $now));
$this->db->stop_cache();
$this->db->flush_cache();
$this->db->start_cache();
$this->db->where('emp_no', $emp_no);
$this->db->where('to_date', '9999-01-01');
$this->db->update('salaries', array('to_date' => $now));
$this->db->stop_cache();
$this->db->flush_cache();
$this->db->start_cache();
$this->db->where('emp_no', $emp_no);
$this->db->where('to_date', '9999-01-01');
$this->db->update('titles', array('to_date' => $now));
$this->db->stop_cache();
$this->db->flush_cache();
return;
} //END REMOVE EMPLOYEE
当我运行这段代码时,它删除了我的记录。我不明白为什么。
我希望它: 更新表WHERE CONDITION_1 AND CONDITION_2 = B
附言:
**$now** is todays date (i.e. 2012-12-25)
**$emp_no** is a unique employee number i.e. 500122
最佳答案
可能的调试方法是注释掉 $this->db->delete()
.
尝试更改这些行:
$this->db->delete('employees', array('emp_no' => $emp_no));
$this->db->flush_cache();
收件人:
//$this->db->delete('employees', array('emp_no' => $emp_no));
//$this->db->flush_cache();
那就试试吧,看看你的记录还在不在。如果您的更新成功并且您的记录仍在表中,则您可能有一个使用删除级联的外键。这意味着如果您从 employees
中删除记录表,您还将删除 dept_emp
中的记录, salaries
和 titles
.
CodeIgniter 事件记录类:http://ellislab.com/codeigniter/user-guide/database/active_record.html
InnoDB 外键:http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html
关于mysql - 在 codeigniter 中使用 Where 和 Where 条件更新 SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14027432/