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
https://forums.phpfreaks.com/topic/79762-insert-or-update-switch/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.