0

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

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);

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?

Thanks. I am a beginner of PHP.

3 Answers 3

4

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));
Sign up to request clarification or add additional context in comments.

Comments

0

Remember that you are deleting these entries in different tables. Each clauses you have are separate to each other so it will not affect each other.

Comments

0

You are doing it right , Just delete the foreign key row from title table then delete the primary key row from the book table.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.