3

これは私のコードです:

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

このコードを実行すると、レコードが削除されました。理由がわかりません。

UPDATE TABLE WHERE CONDITION_1 AND CONDITION_2 = B

PS:

**$now** is todays date (i.e. 2012-12-25)
**$emp_no** is a unique employee number i.e. 500122
4

1 に答える 1

1

これをデバッグする可能な方法は、$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();

次に、それを試して、レコードがまだそこにあるかどうかを確認してください。更新が成功し、レコードがまだテーブルにある場合は、Delete Cascadeを使用して外部キーを取得している可能性があります。つまり、テーブルからレコードを削除すると、 、およびからもレコードが削除されます。employeesdept_empsalariestitles

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

外部キーの確認:テーブルまたは列へのすべての外部キーを確認するにはどうすればよいですか?

于 2012-12-25T04:07:18.613 に答える