|
Posted by NC on 11/19/31 11:47
Colin McKinnon wrote:
>
> There's lots of DB abstraction layers out there, but a quick look around
> them hasn't turned up anything which seems to met my requirements.
Which probably means that you shouldn't even attempt to solve your
problem with an abstraction layer; easier solutions might be
available...
> 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
You don't need PHP code for that; this can be handled on the database
level:
INSERT INTO the_table
SET field1=value1, field2=value2, field3=value3, ...
ON DUPLICATE KEY UPDATE field1=value1, field2=value2, field3=value3,
....
This syntax is available since MySQL 4.1.0.
You could also use a REPLACE query, but keep in mind that it works by
deleting the old record and inserting a new one, so if there are fields
that exist in the table, but not in the query, they will be lost.
Cheers,
NC
Navigation:
[Reply to this message]
|