Automatic ID and Classname import
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;
Re: Automatic ID and Classname import
How can I change the maximum execution time? The script doesn't run for more than 30 seconds.
EDIT: you have to add this line on the top of the script.
Quote:
ini_set('max_execution_time',300);
It will allow the script to run for 5 minutes (300 seconds).
Re: Automatic ID and Classname import
Quote:
Originally Posted by
Anibaaal
How can I change the maximum execution time? The script doesn't run for more than 30 seconds.
Just add the code below to the top of the file, underneath the Comment. More about the maximum execution time: http://php.net/manual/en/function.set-time-limit.php
Code:
set_time_limit(30); // 30 seconds
Re: Automatic ID and Classname import
Oh, I didn't see your reply. Thanks!
I have another question, I modified a part of the script to this:
Quote:
$wallitemtypes = $xml->children();
foreach ($wallitemtypes->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`, `type`) VALUES ('{$id}', '{$classname}', 'i')";
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 />';
}
But it imports everything, roomitemtypes and wallitemtypes. Do you know how to make it import only wallitemtypes furni or that would require a more complex script?
Re: Automatic ID and Classname import
I used this for updating a hotel from azure to Arcturus as azure had set everything to -1 lol.
With a simple JOIN construction you can link on the itemname and update the sprite_id / item_id