Automatic ID and Classname import

Results 1 to 5 of 5
  1. #1
    "(still lacks brains)" NoBrain is offline
    MemberRank
    Sep 2011 Join Date
    United KingdomLocation
    2,658Posts

    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;




  2. #2
    Enthusiast Anibaaal is offline
    MemberRank
    Jan 2015 Join Date
    33Posts

    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.
    ini_set('max_execution_time',300);
    It will allow the script to run for 5 minutes (300 seconds).
    Last edited by Anibaaal; 21-03-15 at 08:58 PM.

  3. #3
    "(still lacks brains)" NoBrain is offline
    MemberRank
    Sep 2011 Join Date
    United KingdomLocation
    2,658Posts

    Re: Automatic ID and Classname import

    Quote Originally Posted by Anibaaal View Post
    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

  4. #4
    Enthusiast Anibaaal is offline
    MemberRank
    Jan 2015 Join Date
    33Posts

    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:

    $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?

  5. #5
    Check http://arcturus.pw The General is offline
    DeveloperRank
    Aug 2011 Join Date
    7,610Posts

    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



Advertisement