Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2871 connectés 

  FORUM HardWare.fr
  Programmation
  PHP

  [PHP] Suppression et modification avec jointure ? c possible ?

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[PHP] Suppression et modification avec jointure ? c possible ?

n°250552
mejero
Posté le 21-11-2002 à 13:09:29  profilanswer
 

Vala en gros j'ai fait un select en utilisant une jointure sur 2 tables login et mail, tout simplement  
 

Code :
  1. 'SELECT * FROM login,mail WHERE login.userid=mail.userid AND login="'.$_POST["login"].'" AND mail="'.$_POST["mail"].'"'


 
Et je voudrais faire une suppression et une modification dans ces 2 tables, donc en gros j'ai ca :
 
Pour modifier :

Code :
  1. 'SELECT * FROM login,mail WHERE login.userid=mail.userid AND login.userid='.$_GET["userid"]


 
Pour supprimer :

Code :
  1. 'DELETE FROM login,mail WHERE login.userid=mail.userid AND login.userid='.$_POST["userid"]


 
Et ca ca marche pas avec cette erreur dans le die pour modifier :
 
 Something is wrong in your syntax près de 'mail SET login="login1",userid="1",home="/home/login1",mail="log' à la ligne 1
 
 
Et pour supprimer : Something is wrong in your syntax près de 'mail WHERE login.userid=mail.userid AND login.userid=1' à la ligne 1
 
 
 
Donc grande question de la mort qui tue : est ce que je me suis trompé dans mon code ? ou bien tout simplement mysql ne sais pas faire de del/update dans 2 tables ?
 

mood
Publicité
Posté le 21-11-2002 à 13:09:29  profilanswer
 

n°250553
Fred999
Rabat-joie
Posté le 21-11-2002 à 13:12:21  profilanswer
 

MySQL ne sait pas faire.
 
D'ailleurs, j'ai jamais vu de double delete/update :D

n°250559
mejero
Posté le 21-11-2002 à 13:19:23  profilanswer
 

Hum
 
Bon j'ai que de vague reste de souvenir de oracle mais c t bien possible nan ? Parce que la ca m'oblige a faire 2 requetes :/ C pas que c bien long, mais je vais avoir un projet d'ici peut de temps ou il y aura surement bcp plus de table, donc une supression ou une modification prendrait x requetes.

n°250573
Fred999
Rabat-joie
Posté le 21-11-2002 à 13:48:04  profilanswer
 

Bin comment dire "beaucoup" de tables ça peut avoir pas mal de significations différentes :D

n°250871
berceker
BERCEKER UNITED
Posté le 21-11-2002 à 18:10:31  profilanswer
 

biensur que c'est possible de le faire!... mais c'est un truc assez complexe car c'est a la creation de ta table qui faut precisé, en fait il sagit de mettre des clé etrangere puis designé les depedance , maintenant quelle est la syntaxe je ne peux pas te dire ,mais je sais que c'est possible,ne cherche pas sur phpmyadmin je ne crois pas qu'il propose cela !
Pour plus de renseignement cherhche dans clé étrangère !....


---------------
Si je suis près de toi c'est soit pour t'embrasser ou te croquer, alors à ce moment là rappelle toi de ce que tu m'as fait. du bien ou du mal?
n°251878
mejero
Posté le 22-11-2002 à 23:50:51  profilanswer
 

Ok, donc si ca existe y'a quelqu'un qui doit bien savoir comment ca se fait nan ?
 
Parce que bon chercher c sympa, mais ca fait des heures et des heures que je cherche pour rien trouver (doc php/mysql, doc nexen, différents sites sur php, quelques forums ...) et ca commence a me saouler un peu.
 
Alors plz help me !
 
PS : je viens de voir que la requete pour le modifier c pas ca, mais j'ai pas le code sous la main pour editer, enfin bn ca ressemble vaguement au delete sauf que c des set ...=... :)

n°252866
omega2
Posté le 25-11-2002 à 12:45:15  profilanswer
 

Je ne penses pas que mysql ai implémenté la gestion des clés étrangères.
Ca viendra surement un jour mais je sais pas quand.

n°252914
Sh@rdar
Ex-PhPéteur
Posté le 25-11-2002 à 14:02:24  profilanswer
 

:non:  
 
joce va encore raler sinon :D  
 
3.5.6 Using Foreign Keys
 
In MySQL 3.23.44 and up, InnoDB tables supports checking of foreign key constraints. See section 7.5 InnoDB Tables. See also section 1.7.4.5 Foreign Keys.
 
You don't actually need foreign keys to join 2 tables. The only thing MySQL currently doesn't do (in table types other than InnoDB), is CHECK to make sure that the keys you use really exist in the table(s) you're referencing and it doesn't automatically delete rows from a table with a foreign key definition. If you use your keys like normal, it'll work just fine:  


---------------
La musique c'est comme la bouffe, tu te souviens du restaurant dans lequel t'as bien mangé 20 ans plus tôt, mais pas du sandwich d'il y a 5 minutes :o - Plugin pour winamp ©Harkonnen : http://harko.free.fr/soft
n°252921
Sh@rdar
Ex-PhPéteur
Posté le 25-11-2002 à 14:13:33  profilanswer
 

après recherche
 
oui les clefs étrangères sont supportées (comme écrit plus haut) mais j'ai pas l'impression que l'effacement sur des tables multiples soit possible..
 
1.7.4.5 Foreign Keys
 
Note that foreign keys in SQL are not used to join tables, but are used mostly for checking referential integrity (foreign key constraints). If you want to get results from multiple tables from a SELECT statement, you do this by joining tables:
 
SELECT * FROM table1,table2 WHERE table1.id = table2.id;
 
See section 6.4.1.1 JOIN Syntax. See section 3.5.6 Using Foreign Keys.
 
In MySQL Server 3.23.44 and up, InnoDB tables support checking of foreign key constraints. See section 7.5 InnoDB Tables. For other table types, MySQL Server does parse the FOREIGN KEY syntax in CREATE TABLE commands, but without further action being taken.
 
The FOREIGN KEY syntax without ON DELETE ... is mostly used for documentation purposes. Some ODBC applications may use this to produce automatic WHERE clauses, but this is usually easy to override. FOREIGN KEY is sometimes used as a constraint check, but this check is unnecessary in practice if rows are inserted into the tables in the right order.
 
In MySQL Server, you can work around the problem of ON DELETE ... not being implemented by adding the appropriate DELETE statement to an application when you delete records from a table that has a foreign key. In practice this is as quick (in some cases quicker) and much more portable than using foreign keys.
 
In MySQL Server 4.0 you can use multi-table delete to delete rows from many tables with one command. See section 6.4.6 DELETE Syntax.
 
In the near future we will extend the FOREIGN KEY implementation so that the information will be saved in the table specification file and may be retrieved by mysqldump and ODBC. At a later stage we will implement the foreign key constraints for applications that can't easily be coded to avoid them.
 
Do keep in mind that foreign keys are often misused, which can cause severe problems. Even when used properly, it is not a magic solution for the referential integrity problem, although it does make things easier in some cases.
 
Some advantages of foreign key enforcement:
 
    * Assuming proper design of the relations, foreign key constraints will make it more difficult for a programmer to introduce an inconsistency into the database.
    * Using cascading updates and deletes can simplify the client code.
* Properly designed foreign key rules aid in documenting relations between tables.
 
Disadvantages:
 
    * Mistakes, which are easy to make in designing key relations, can cause severe problems?for example, circular rules, or the wrong combination of cascading deletes.
    * A properly written application will make sure internally that it is not violating referential integrity constraints before proceding with a query. Thus, additional checks on the database level will only slow down performance for such an application.
* It is not uncommon for a DBA to make such a complex topology of relations that it becomes very difficult, and in some cases impossible, to back up or restore individual tables.


---------------
La musique c'est comme la bouffe, tu te souviens du restaurant dans lequel t'as bien mangé 20 ans plus tôt, mais pas du sandwich d'il y a 5 minutes :o - Plugin pour winamp ©Harkonnen : http://harko.free.fr/soft
n°252996
omega2
Posté le 25-11-2002 à 15:18:13  profilanswer
 

Ben a quoi ca sert de déclarer des clé étrangère si tout ce qui est lié aux clé étrangère n'est pas implémenté?
 
Si a la création, mysql ne vérifie pas qu'une clé primère corespondante à la clé étrangère n'existe pas et qu'à la supression, ca supprime que la clé primaire sans tester l'existance et sans supprimer les lignes ayant des clés secondaires corespondantes alors je vois pas l'intéret d'utiliser des clés étrangères.
 
 
 
Bon, il reste visiblement la solution de la création des tables en InnoDB pour avoir les clé étrangères qui fonctionne mais moi, je le fais pas, ne conaissant pas les limitations et les avantages de ce type de table par rapport au type de table mis par défaut par mysql.

mood
Publicité
Posté le 25-11-2002 à 15:18:13  profilanswer
 

n°253346
mejero
Posté le 25-11-2002 à 19:25:48  profilanswer
 

Ah bah voila un peu d'indices pour avancer :)
 
Je vais plencher un coup la dessus pour voir ce qu'on peut faire ;)


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  PHP

  [PHP] Suppression et modification avec jointure ? c possible ?

 

Sujets relatifs
[PHP] saucissonnner une chaine de characterePHP et MySQL que choisir comme guide de reference? (book papier)
Récupérer le temps en ms, c possible ? -ntProblème PHP/MySQL assez complexe
[PHP] Formulaires.... ???[PHP] Upload de fichier (Chez FREE)
[PHP] Problème de confirmation d'inscription avec un formulaire.[PHP] phpbb?
Executer un script PHP à partir dun script perl ....[PHP/MYSQL] - alors la si qqun y comprends qque chose, CHAPO! [résolu]
Plus de sujets relatifs à : [PHP] Suppression et modification avec jointure ? c possible ?


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR