Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MYSQL inserting multiple rows unexpectedly

I'm having an issue and was hoping that someone could help me out.

My issue is that whenever I run the code in the "MainFile", It outputs the two ID's that it has added the entries at, but then when I view my database I have six entries instead of two... Could anyone tell me why it might be doing this?

Note: I've only supplied snippets of the code from the classes because supplying the full classes would be way too much code. This is the only code be executed though.

CODE IN EDIT HISTORY

Edit: I've added a debug log to the bottom of this post verifying that I'm only executing the SQL code once for each query.

Edit: I'm no longer using the serialization method as it is clearly a bad idea for storing this type of data. However, even with my new code that is storing each individual value within the database I'm still getting three entries instead of one. So, it's the same issue. Anything?

Edit: After a few days of debugging I have narrowed it down to this line that is causing the issue

Throwlite::$systemSQL->executeSql("INSERT into ".SQL_COMMENTTHREADS_TABLE." (id, sort_order) values (DEFAULT, '2')");

You can view the LiteSQL class here for reference: http://pastebin.com/a4C6fF4u

Also, For reference, Here is the code being used to create the Table:

"CREATE TABLE IF NOT EXISTS `" . SQL_COMMENTTHREADS_TABLE . "` (`id` int unsigned NOT NULL AUTO_INCREMENT, `sort_order` int NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;"

And, Even though I'm pretty sure it shouldn't matter, Here is where SQL_COMMENTTHREADS_TABLE is bing defined.

define( 'SQL_COMMENTTHREADS_TABLE', "tl_comment_threads");
like image 270
Nathan F. Avatar asked May 29 '15 08:05

Nathan F.


1 Answers

I'm not sure this answers your question, but you seem to be specifying the ID that you are inserting. I'm not sure whether you aren't using a PRIMARY KEY on your id column or why this works at all, but maybe you want this:

INSERT INTO " . SQL_COMMENTS_TABLE . " (id, thread) VALUES (DEFAULT, ?)

like image 62
Jonathan Card Avatar answered Sep 28 '22 20:09

Jonathan Card