Why is CodeIgniter adding an extra "where" to my delete query? <p>For some reason, CodeIgniter is adding an extra "where" clause to my delete query. It's obvious as to why the MySQL error is happening... but why is CI adding this extra clause?</p> <p>This is the error:</p> <pre><code>Unknown column '8' in 'where clause' DELETE FROM `forum_messages` WHERE `thread_id` = '8' AND `8` IS NULL </code></pre> <p>This is my code:</p> <pre><code>function delete($thread_id){ $this-&gt;db-&gt;save_queries = FALSE; $this-&gt;db-&gt;where('thread_id', $thread_id); if(!$this-&gt;db-&gt;delete('forum_messages')){ $this-&gt;error = "The messages in this thread could not be deleted because of a database error: ".$this-&gt;db-&gt;_error_message(); } else { $this-&gt;db-&gt;where('thread_id', $thread_id); if(!$this-&gt;db-&gt;delete('forum_threads')){ $this-&gt;error = "The thread could not be deleted because of a database error: ".$this-&gt;db-&gt;_error_message(); } } } </code></pre> <p>UPDATE:</p> <p>None of the answers suggested below worked. For some reason I had to switch the delete queries and delete from forum_messages before I deleted before forum_threads.</p>