Automatic ID and Classname import
What is this?
This simple little script takes all the IDs and Classname's from the Furnidata XML file and imports them into a table within the database. Not sure what you could possibly use this for but here you go.
Code
PHP:
Code:<?php /** * Reads XML and inserts ID and Classname into Database * * Author: nobrain */ $xml = simplexml_load_file("furnidata_xml.xml"); $connection = mysqli_connect("localhost", "root", "PASSWORD", "DATABASE", "3306") or die("Failed to connect"); echo "<h2>".$xml->getName()."</h2><br />"; $roomitemtypes = $xml->children(); foreach ($roomitemtypes->children() as $furnitype) { echo 'ID: ' . $furnitype['id'] . '<br />'; echo 'Classname: ' . $furnitype['classname'] . '<br /><hr />'; $id = $furnitype['id']; $classname = $furnitype['classname']; $query = "INSERT INTO `items_list` (`id`, `class`) VALUES ('{$id}', '{$classname}')"; mysqli_query($connection, $query) or die("Failed to import"); echo '<b>' . $furnitype['id'] . '</b> and <b>' . $furnitype['classname'] . '</b> have been imported to the database!<br />'; }
SQL:
Code:CREATE TABLE IF NOT EXISTS `items_list` ( `id` int(11) DEFAULT NULL, `class` varchar(256) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8;



Reply With Quote


