PHP : gestion fichiers xml
Posté : 21 févr. 2013, 15:59
bonjour ,
voilà je travail sur phpMyAdmin , j'ai deux tables de test : "ancienne" et "nouvelle" dont voici les fichiers xml : ( je voudrais importer dans la table nouvelle les occurrences de l'ancienne table pour cela j'ai pensé à faire une lecture grâce à : simplexml_load_file mais lorsque dans phpMyAdmin j'importe mon script ça ne fonctionne pas )
<pma:database name="testXml" collation="latin1_swedish_ci" charset="latin1">
<pma:table name="ancienne">
CREATE TABLE `ancienne` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nom` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
</pma:table>
</pma:database>
</pma:structure_schemas>
<!--
- Base de données: 'testXml'
-->
<database name="testXml">
<!-- Table ancienne -->
<table name="ancienne">
<column name="id">1</column>
<column name="nom">bob</column>
</table>
<table name="ancienne">
<column name="id">2</column>
<column name="nom">toto</column>
</table>
</database>
</pma_xml_export>
et pour la nouvelle :
<pma:structure_schemas>
<pma:database name="testXml" collation="latin1_swedish_ci" charset="latin1">
<pma:table name="nouvelle">
CREATE TABLE `nouvelle` (
`nouv_id` int(11) NOT NULL AUTO_INCREMENT,
`nouv_name` text NOT NULL,
`date` datetime NOT NULL,
PRIMARY KEY (`nouv_id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
</pma:table>
</pma:database>
</pma:structure_schemas>
<!--
- Base de données: 'testXml'
-->
<database name="testXml">
<!-- Table nouvelle -->
<table name="nouvelle">
<column name="nouv_id">1</column>
<column name="nouv_name">titi</column>
<column name="date">2013-02-21 13:00:51</column>
</table>
</database>
</pma_xml_export>
script : <?php
$test_xml = simplexml_load_file('test.xml');
foreach ($ancienne ->ancienne as $ancienne) {
print "Id : {$ancienne->id} <hr />\n";
print "Nom : {$acienne->nom} <br />\n";
mysql_query("INSERT INTO nouveau SET nouv_id='".($ancienne->id)."' AND nouv_name='".($ancienne->nom)."'") or die("Erreur MySQL : ".mysql_error());
}
?>
pourriez vous me débloquer svp
voilà je travail sur phpMyAdmin , j'ai deux tables de test : "ancienne" et "nouvelle" dont voici les fichiers xml : ( je voudrais importer dans la table nouvelle les occurrences de l'ancienne table pour cela j'ai pensé à faire une lecture grâce à : simplexml_load_file mais lorsque dans phpMyAdmin j'importe mon script ça ne fonctionne pas )
<pma:database name="testXml" collation="latin1_swedish_ci" charset="latin1">
<pma:table name="ancienne">
CREATE TABLE `ancienne` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nom` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
</pma:table>
</pma:database>
</pma:structure_schemas>
<!--
- Base de données: 'testXml'
-->
<database name="testXml">
<!-- Table ancienne -->
<table name="ancienne">
<column name="id">1</column>
<column name="nom">bob</column>
</table>
<table name="ancienne">
<column name="id">2</column>
<column name="nom">toto</column>
</table>
</database>
</pma_xml_export>
et pour la nouvelle :
<pma:structure_schemas>
<pma:database name="testXml" collation="latin1_swedish_ci" charset="latin1">
<pma:table name="nouvelle">
CREATE TABLE `nouvelle` (
`nouv_id` int(11) NOT NULL AUTO_INCREMENT,
`nouv_name` text NOT NULL,
`date` datetime NOT NULL,
PRIMARY KEY (`nouv_id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
</pma:table>
</pma:database>
</pma:structure_schemas>
<!--
- Base de données: 'testXml'
-->
<database name="testXml">
<!-- Table nouvelle -->
<table name="nouvelle">
<column name="nouv_id">1</column>
<column name="nouv_name">titi</column>
<column name="date">2013-02-21 13:00:51</column>
</table>
</database>
</pma_xml_export>
script : <?php
$test_xml = simplexml_load_file('test.xml');
foreach ($ancienne ->ancienne as $ancienne) {
print "Id : {$ancienne->id} <hr />\n";
print "Nom : {$acienne->nom} <br />\n";
mysql_query("INSERT INTO nouveau SET nouv_id='".($ancienne->id)."' AND nouv_name='".($ancienne->nom)."'") or die("Erreur MySQL : ".mysql_error());
}
?>
pourriez vous me débloquer svp