How to: Import iConomy balances to MySQL!

Discussion in 'Bukkit Help' started by ryanshawty, Feb 5, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    ryanshawty

    Do you want to import all your iConomy balances from flat file to a MySQL database?
    Well I made this quick script to import mine, so I posted it to share :)
    Just put this on your web server with balances.txt in the same directory and navigate to the PHP file.

    PHP:
    <?php
    // Variables for MySQL config
    $file "balances.txt";
    $user "db_user";
    $pass "db_user_pass";
    $DB "database_name";

    // Connect to database
    mysql_connect("localhost"$user$pass) or die(mysql_error());
    mysql_select_db($DB) or die(mysql_error());

    // Open local file
    $handle fopen($myFile'r');

    // Import data to database
    while (!feof($handle)) {
        
    $data fgets($handle512);
        
    $dataarray explode("="$data);
        
    $player $dataarray[0];
        
    $balance = (int)$dataarray[1];
        
    mysql_query("INSERT INTO iBalances (player,balance,id) VALUES ('$player','$balance',NULL)") or die(mysql_error());
        echo 
    $player." with balance: ".$balance.". <font color=green>Success!</font></br>";
    }
    fclose($handle);
    ?>
     
  2. Offline

    TnT

    Awesome script. I can't use it myself, but its great to see.

    Do you have a script to convert it to SQLite DB's as well? That would be preferred for me.
     
  3. Offline

    ryanshawty

    Sorry, never used SQLite. I will look into it and post back with anything :)
    --- merged: Feb 5, 2011 6:44 PM ---
    Right, give this a shot, I haven't tested it thought.
    PHP:
    <?php
    // Variables for SQLite config
    $file "balances.txt";
    $DB "database_name"//SQLite file name

    // Connect to database
    $dbhandle sqlite_open($DB0666$sqliteerror);

    // Open local file
    $handle fopen($myFile'r');

    // Import data to database
    while (!feof($handle)) {
        
    $data fgets($handle512);
        
    $dataarray explode("="$data);
        
    $player $dataarray[0];
        
    $balance = (int)$dataarray[1];
       
    sqlite_query("INSERT INTO iBalances (player,balance,id) VALUES ('$player','$balance',NULL)") or die(mysql_error());
        echo 
    $player." with balance: ".$balance.". <font color=green>Success!</font></br>";
    }
    fclose($handle);
    ?>
    --- merged: Feb 5, 2011 8:51 PM ---
    I also made one to import shop data to MySQL for the plugin SimpleShop from iCShop data file, if anyone wants just drop me a message :)
     
Thread Status:
Not open for further replies.

Share This Page