php tools
#2

class_lcfile.php

<?php     class LCFile    {         var $fp;         /**         * Creates a new binary file to write to         * @param string $fileName The name of the file to create         */        function Create($fileName)        {            $this->fp = fopen($fileName, 'wb');             if ( !$this->fp )                return false;             return true;        }         /**         * Write a signed 32bit integer to the file         * @param int $val the integer to write to the file         */        function WriteInt($val)        {            fwrite($this->fp, pack('l', $val));        }         /**         * Writes a signed short to the file         * @param short $val the value to write to the file          */        function WriteShort($val)        {            fwrite($this->fp, pack('s', $val));        }         /**         * Writes a signed byte to the file         * @param byte $val the value to write to the file          */        function WriteByte($val)        {            fwrite($this->fp, pack('C', $val));        }         /**         * Writes a float to the file         * @param float $val the value to write to the file          */        function WriteFloat($val)        {            fwrite($this->fp, pack('f', $val));        }         /**         * Writes a string to the file         * @param string $val the value to write to the file          */        function WriteString($val)        {            if ( strlen($val) > 0 )            {                $this->WriteInt(strlen($val));                fwrite($this->fp, $val);            }            else                $this->WriteInt(0);        }     } ?>

 
 
 
rareoption.php

<?php     mysql_connect('localhost', 'root', 'root');    mysql_select_db('newproject_data');             require_once 'class_lcfile.php';            // Create a new file    $file = new LCFile();    if(!$file->Create('rareoption_usa.lod'))    die('Cannot create file');                // Get max id    $result = mysql_query("SELECT max(a_index) FROM t_rareoption");    $row = mysql_fetch_row($result);    $max = $row[0];            // Write max id    $file->WriteInt($max);      // Get all records    $result = mysql_query("SELECT * FROM t_rareoption ORDER BY a_index");    while($r = mysql_fetch_array($result))    {         $file->WriteInt($r['a_index']);        $file->WriteInt($r['a_grade']);        $file->WriteInt($r['a_type']);        $file->WriteString($r['a_prefix_usa']);        $file->WriteInt($r['a_attack']);        $file->WriteInt($r['a_defense']);        $file->WriteInt($r['a_magic']);        $file->WriteInt($r['a_resist']);                for($i=0; $i<10; $i++)        {            $file->WriteInt($r['a_option_index'.$i]);            $file->WriteInt($r['a_option_level'.$i]);        }    }     echo 'Done!'; ?>

 
 
 



Messages In This Thread
[No subject] - by Tano - 07-23-2014, 04:44 AM
[No subject] - by Wizatek - 07-23-2014, 05:42 AM
[No subject] - by Walletman987 - 07-23-2014, 05:56 AM
[No subject] - by Tano - 07-23-2014, 01:51 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)