问题描述
我要删除我的数据库的一个表中的条目。表名为 book 。但在表格 title 中使用外键。
I want to delete an entry in one table of my database. The table name is book. But in table title use foreign key book.
book: id, name
title: id, book_id, title
现在我要删除 book >。因此,我必须删除 title 表中的相关条目。我的代码是:
Now I want to delete an entry in book. So, I have to delete related entries in title table. My code is :
$this->db->where(book_id,$deleteid);
$this->db->delete(title);
$this->db->where(id,$deleteid);
$this->db->delete(book);
我的问题是第一个 where子句是否会影响我的第二个 delete子句?
如果它影响第二个,我该怎么做,以避免这种情况?
My question is whether the first where clause will affect my second delete clause?If it affects the second one, what should I do to avoid this?
谢谢。我是PHP的初学者。
Thanks. I am a beginner of PHP.
推荐答案
没有第一个其中
不影响第二个 delete
。
No the first where
won't affect the second delete
.
>
You may find it more intuitive if you rewrite it like this
$this->db->delete('title', array('book_id' => $deleteid));
$this->db->delete('book', array('id' => $deleteid));
这篇关于PHP使用codeigniter从数据库中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!