Précédent   Forum des professionnels en informatique > PHP > Langage > Fonctions
Fonctions Forum d'entraide sur les fonctions PHP. Avant de poster -> FAQ fonctions et Sources diverses
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 18/10/2011, 09h47   #1
Nouveau Membre du Club
 
Inscription : novembre 2008
Messages : 180
Détails du profil
Informations forums :
Inscription : novembre 2008
Messages : 180
Points : 28
Points : 28
Par défaut Query to XML

Bonjour,

J'ai une requete dans ma viarable $sql et j'aimerai que le résultat de ma requette soit sous format XML...il n'y a pas de fonction en SQL pour le format XML ? un INTO FILE ......
Comment je peux faire...

Merci à vous
tidou95220 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/10/2011, 10h27   #2
Membre Expert
 
Avatar de transgohan
 
Homme Baptiste ROUSSEL
Étudiant
Inscription : janvier 2011
Messages : 808
Détails du profil
Informations personnelles :
Nom : Homme Baptiste ROUSSEL
Localisation : France, Territoire de Belfort (Franche Comté)

Informations professionnelles :
Activité : Étudiant

Informations forums :
Inscription : janvier 2011
Messages : 808
Points : 1 523
Points : 1 523
Ton retour de requête est un array, donc tu peux convertir cet array en XML via la class SimpleXML.

Un début de réponse tiré de Stackoverflow :
Code php :
1
2
3
4
5
6
7
8
9
10
$test_array = array (
  'bla' => 'blub',
  'foo' => 'bar',
  'another_array' => array (
    'stack' => 'overflow',
  ),
);
$xml = new SimpleXMLElement('<root/>');
array_walk_recursive($test_array, array ($xml, 'addChild'));
print $xml->asXML();
Citation:
<?xml version="1.0"?>
<root>
<blub>bla</blub>
<bar>foo</bar>
<overflow>stack</overflow>
</root>
Source : http://stackoverflow.com/questions/1...397164#1397164
__________________
Toujours se souvenir que la majorité des ennuis viennent de l'espace occupé entre la chaise et l'écran de l'ordinateur.
transgohan est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/10/2011, 10h41   #3
Nouveau Membre du Club
 
Inscription : novembre 2008
Messages : 180
Détails du profil
Informations forums :
Inscription : novembre 2008
Messages : 180
Points : 28
Points : 28
Code :
$req = mysql_query($finalrequete) or die('Erreur SQL !<br>'.$finalrequete.'<br>'.mysql_error());
$req est un tableau ? quand je fait un var_dump il me dit bolean
tidou95220 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/10/2011, 10h50   #4
Nouveau Membre du Club
 
Inscription : novembre 2008
Messages : 180
Détails du profil
Informations forums :
Inscription : novembre 2008
Messages : 180
Points : 28
Points : 28
mysql_fetch_assoc()..... mysql_fetch_array()
tidou95220 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/10/2011, 10h51   #5
Nouveau Membre du Club
 
Inscription : novembre 2008
Messages : 180
Détails du profil
Informations forums :
Inscription : novembre 2008
Messages : 180
Points : 28
Points : 28
ça me sort un résultat un peux étrange mais je vais aller dans ce sens pour ma recherche merci
tidou95220 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/10/2011, 12h46   #6
Nouveau Membre du Club
 
Inscription : novembre 2008
Messages : 180
Détails du profil
Informations forums :
Inscription : novembre 2008
Messages : 180
Points : 28
Points : 28
Me sort un fichier test.xml parfait ^^

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
echo $without_into;
//$sql = "SELECT * FROM auto_a WHERE pays = 'Allemagne' AND STR_TO_DATE(dates, '%d/%m/%Y') BETWEEN '2008-01-01' AND '2019-01-01'";
$q	 = mysql_query($without_into) or die(mysql_error("Erreur"));
$xml = "<library>";
//var_dump(mysql_fetch_array($q));
while($r = mysql_fetch_array($q)){
  $xml .= "<items>";
  $xml .= "<pays>".$r['pays']."</pays>";  
  $xml .= "<indicateur>".$r['indicateur']."</indicateur>";
  $xml .= "<periodicite>".$r['periodicite']."</periodicite>";      
  $xml .= "<source>".$r['source']."</source>";  
  $xml .= "<unite1>".$r['unite1']."</unite1>";
  $xml .= "<unite2>".$r['unite2']."</unite2>";
  $xml .= "<unite3>".$r['unite3']."</unite3>"; 
  $xml .= "<unite4>".$r['unite4']."</unite4>";
  $xml .= "<unite5>".$r['unite5']."</unite5>";
  $xml .= "<dates>".$r['dates']."</dates>";
  $xml .= "<valeur>".$r['valeur']."</valeur>";
  $xml .= "</items>";  
}
$xml .= "</library>";
$sxe = new SimpleXMLElement($xml);
$sxe->asXML("test.xml");
tidou95220 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 05h19.


 
 
 
 
Partenaires

Hébergement Web