Jump to content

Insert or Update Switch


techtheatre

Recommended Posts

I have a script that needs to update a record in a database (standard UPDATE query).  Unfortunately, this script is in a general function used by a variety of processes in my scripts, and occasionally there is no record to update, so i would need to use an INSERT query.  Is there another type of query besides INSERT and UPDATE that will instead UPDATE if it exists, and if not, INSERT?...  Currently i have to run an extra query just to see if it exists before i can run the actual query that i need to run...surely there is a better way...some sort of conditional insert/update...  Thanks!

Link to comment
Share on other sites

the only close is this.

 

http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html

 

but that is in the wrong direction of what you want.

 

what I dont understand is you not being able to update your global function, you just make it so it responds as it did when it was just an update but have it do insert with the values.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.