|
|
|
#1 (permalink) |
|
Messages: n/a
Hébergeur: |
Sorry for the newbie question here... but I haven't been able to figure
this out searching the web. 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. Is this done through a simple SQL command, or do I need to use PHP to negotiate two separate UPDATE and INSERT statements? |
|
|
|
#2 (permalink) |
|
Messages: n/a
Hébergeur: |
You are looking for an object-relationnal mapping. This can do that (and
much more). But PHP is a beginner with objects. For now, this can be found in Java, C++ languages only. Pierre "dx27s" <dx27s@yahoo.com> a écrit dans le message de news: Bxs%f.10345$1q4.3243@bgtnsc05-news.ops.worldnet.att.net... > Sorry for the newbie question here... but I haven't been able to figure > this out searching the web. > > 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. > > Is this done through a simple SQL command, or do I need to use PHP to > negotiate two separate UPDATE and INSERT statements? |
|
|
|
#3 (permalink) |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#4 (permalink) |
|
Messages: n/a
Hébergeur: |
"Pierre Gilquin" <pgilquin@bluewin.chAvirer> wrote in
news:443e5a26$1_2@news.bluewin.ch: > You are looking for an object-relationnal mapping. This can do that > (and much more). But PHP is a beginner with objects. For now, this can > be found in Java, C++ languages only. ????? |
|
![]() |
| Outils de la discussion | |
|
|