Afficher un message
Vieux 13/04/2006, 17h29   #3
Bill Karwin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie q: update and/or insert?

dx27s wrote:
> I'm using MySQL with PHP. I want to update a record if it already
> exists. If it does not exist, I need to create a new record.


This can be done either with the REPLACE statement, or the INSERT...ON
DUPLICATE KEY UPDATE. These two statements are subtly different.

REPLACE literally deletes an existing record and inserts a new one in
its place, using the values you specify. This means you need to provide
values for all the columns in your statement.

INSERT...ON DUPLICATE KEY UPDATE allows you to modify individual columns
in the case of an existing record, and leave the others alone. This was
added in MySQL 4.1.

Read the docs for more information:
http://dev.mysql.com/doc/refman/5.0/...duplicate.html
http://dev.mysql.com/doc/refman/5.0/en/replace.html

Regards,
Bill K.
  Réponse avec citation
 
Page generated in 0,05088 seconds with 9 queries