|
Posted by Jim Moseby on 07/01/05 23:44
>
> I have a very simple script that has to either INSERT a record if one
> doesn't exist or UPDATE one if it does (the table has a unique index
> on 2 fields). So, i am using PEAR DB and i was hoping to do an INSERT,
> then trap any resulting error and if it creates an error (assume it is
> caused by a duplicate) and do the UPDATE.
>
> My problem is, i always get an error ("DB Error: already exists"),
> even if i preceed the $db->query() with @ ... or i switch
> error_reporting(0). It never allows me to do my own error handling.
>
> How should i be doing this? Am i on the right track? :-s
I know absolutely nothing about PEAR, but it seems to me that you would want
to use REPLACE.
<pseudocode>
"REPLACE into tablename (column1, column2...) values (value1, value2...)"
</pseudocode>
REPLACE will create a new record if one does not exist, and will replace an
existing record if it does.
JM
[Back to original message]
|