techtheatre Posted December 2, 2007 Share Posted December 2, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/79762-insert-or-update-switch/ Share on other sites More sharing options...
BenInBlack Posted December 2, 2007 Share Posted December 2, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/79762-insert-or-update-switch/#findComment-404058 Share on other sites More sharing options...
fenway Posted December 2, 2007 Share Posted December 2, 2007 What are you trying to update? The same record? Related records? Summary tables? Quote Link to comment https://forums.phpfreaks.com/topic/79762-insert-or-update-switch/#findComment-404194 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.