Précédent   Forum des professionnels en informatique > Bases de données > MySQL > SQL Procédural
SQL Procédural Forum d'entraide sur les triggers, les procédures stockées et les fonctions en MySQL
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 09/04/2007, 11h43   #1
Membre du Club
 
Inscription : décembre 2006
Messages : 180
Détails du profil
Informations forums :
Inscription : décembre 2006
Messages : 180
Points : 63
Points : 63
Par défaut Insertion multiples via script php

Bonjour,

Dans un script php j'aimerai faire des insertions multiples dans ma base de donnée. En fait j'ai environ 1000 insertion à faire.
Quelle commande utilisée pour faire cela ?
Faut t'il faire un mysql_query(" "); pour chaque INSERT ? Ce qui ferai 1000 mysql_query .. Ou existe t'il une commande qui permet d'exécuter les insertions à la suite ?

Merci
furtif1 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/04/2007, 12h28   #2
Invité régulier
 
Inscription : avril 2007
Messages : 21
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 21
Points : 6
Points : 6
Et bien tu fait une boucle For :

For(i==0,i<=1000,i++)
{
//Tu fait le Insert
}
Jordan59 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/04/2007, 15h28   #3
Membre du Club
 
Inscription : décembre 2006
Messages : 180
Détails du profil
Informations forums :
Inscription : décembre 2006
Messages : 180
Points : 63
Points : 63
Non je ne penses pas que ce soit possible, voici un exemple :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
INSERT INTO phpbb_config (config_name, config_value) VALUES ('active_sessions', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_attachments', '1');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_autologin', '1');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_avatar_local', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_avatar_remote', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_avatar_upload', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_bbcode', '1');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_bookmarks', '1');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_emailreuse', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_forum_notify', '1');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_mass_pm', '1');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_name_chars', '.*');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_namechange', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_nocensors', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_pm_attach', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('allow_post_links', '1');
Comment faire pour par exemple insérer sa en une seul commande ?
furtif1 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/04/2007, 17h03   #4
Membre expérimenté
 
Inscription : septembre 2006
Messages : 685
Détails du profil
Informations forums :
Inscription : septembre 2006
Messages : 685
Points : 564
Points : 564
On peut faire bien entendu plusieurs INSERT en une commande.

Code SQL :
1
2
3
4
5
6
7
INSERT INTO phpbb_config (config_name, config_value)
VALUES
('active_sessions', '0'), 
('allow_attachments', '1'), 
....
....
('allow_post_links', '1');
Xunil est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 09h52.


 
 
 
 
Partenaires

Hébergement Web