PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Logiciels d'hébergement > mailing.database.mysql > newbie q: update and/or insert?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
newbie q: update and/or insert?

Réponse
 
LinkBack Outils de la discussion
Vieux 13/04/2006, 15h40   #1
dx27s
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut newbie q: update and/or insert?

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?
  Réponse avec citation
Vieux 13/04/2006, 16h03   #2
Pierre Gilquin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie q: update and/or insert?

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?



  Réponse avec citation
Vieux 13/04/2006, 18h29   #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
Vieux 13/04/2006, 21h28   #4
Good Man
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: newbie q: update and/or insert?

"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.


?????

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h03.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08135 seconds with 12 queries