|
Posted by Toby Inkster on 11/19/32 11:47
Iván Sánchez Ortega wrote:
> Colin McKinnon wrote:
>
>> I want some code where I present an array of data, and the corresponding
>> primary key and let the code work out whether to INSERT or UPDATE it,[...]
> [...]
>> Anybody any suggestions?
>
> Use MySQL and REPLACE statements.
Very abstract.
One technique for the OP might be to prepare both an INSERT and an UPDATE
statement. Run the INSERT statement; if it fails then there's probably
already a row with that primary key, so run the UPDATE statement. Or you
could run UPDATE first, check the number of rows updated; if 0, run the
INSERT. Not particularly clean, but should be quite portable.
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Navigation:
[Reply to this message]
|