NYCPHP Meetup

NYPHP.org

[nycphp-talk] Insert updating instead of inserting

Bruce Martin bmartin at mac.com
Mon Oct 3 09:03:25 EDT 2011


I think, I have resolved the issue. I was not using on duplicate key, but after reading through the documentation about auto_increment, I decided to include an Id, the primary auto_incremented field in the insert statement and assign it a value of null. This seems to force the auto_increment to do it's thing instead of updating.

Bruce Martin
The Martin Solution
Bruce at martinsolution.com
http://www.martinsolution.com

On Sep 30, 2011, at 07:13 PM, Federico Ulfo <rainelemental at gmail.com> wrote:

Weird issue, are you using INSERT INTO ... ON DUPLICATE KEY ... UPDATE?
http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html

Also if you don't want to receive any MySql error from the INSERT query you might want to user INSERT IGNORE, it won't do nothing if the row you're inserting is already there.

Just in case you don't find a simple solution, you can create a pipeline for the chron job and let him handle all the insert queries.



On Fri, Sep 30, 2011 at 7:00 PM, Dan Cech <dcech at phpwerx.net> wrote:
Bruce,


I have an issue I hope someone can help me figure out. We have a Mysql database
two php processes that insert new records into a table. There should never be a
time when these processes update a record they should only insert a new one.
These processes run simultaneously one running from a cron job and the other
running when requested is made via an ajax call.

For some reason when each process is working at the same time It seems to not
insert a new record but update a similar record. I am explicitly calling insert
and I do not include the primary_key id in the insert statement.

Can you post the output from SHOW CREATE TABLE and an example of the queries you're running?

Also, please don't create a new topic by hitting reply and changing the subject, it breaks threading in most mail clients.

Dan
_______________________________________________
New York PHP Users Group Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

http://www.nyphp.org/Show-Participation

_______________________________________________
New York PHP Users Group Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

http://www.nyphp.org/Show-Participation
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20111003/7aeafaf0/attachment.html>


More information about the talk mailing list