Jump to content

Importing the data from a TXT file to a MySQL DB.


kelphyr

Recommended Posts

I need help, basicly I'm not quite sure where to start. I'm trying to make a php script that could import the data from a text file to a mysql database. But I'm not quite good with reading files.

 

This is my MYSQL DB

CREATE TABLE `item_db` (
`id` INT( 10 ) NOT NULL ,
`aegisname` TEXT NOT NULL ,
`name` TEXT NOT NULL ,
`type` TINYINT( 2 ) NOT NULL ,
`price` INT( 10 ) NOT NULL ,
`sell` INT( 10 ) NOT NULL ,
`weight` INT( 10 ) NOT NULL ,
`atk` INT( 10 ) NOT NULL ,
`def` INT( 10 ) NOT NULL ,
`range` TINYINT( 1 ) NOT NULL ,
`slot` TINYINT( 1 ) NOT NULL ,
`job` TEXT NOT NULL ,
`upper` TINYINT( 1 ) NOT NULL ,
`gender` TINYINT( 1 ) NOT NULL ,
`loc` INT( 10 ) NOT NULL ,
`wlv` TINYINT( 2 ) NOT NULL ,
`elv` TINYINT( 2 ) NOT NULL ,
`refineable` TINYINT( 1 ) NOT NULL ,
`view` TINYINT( 2 ) NOT NULL ,
`script` TEXT NOT NULL ,
`equip_scr` TEXT NOT NULL ,
`unequip_scr` TEXT NOT NULL 
) TYPE = MYISAM ;

 

My text file is separated by "," and has hundred of lines.

example code from it.

//ID,AegisName,Name,Type,Price,Sell,Weight,ATK,DEF,Range,Slot,Job,Upper,Gender,Loc,wLV,eLV,Refineable,View,{ Script },{ OnEquip_Script },{ OnUnequip_Script }
2501,Hood,Hood,5,1000,,200,,1,,0,0xFFFFFFFF,7,2,4,,0,1,0,{},{},{}

 

Could anyone show me how to read the file and inject it, into my sql db? (if possible it should not read the lines starting with // )

 

This would be soo much appreciated, it's for a game... for references on items and such. (it's for me and my friends basicly.)

Got this so far(check below), my main problem is how to check for end of line, AND how to like..

 

read this, read this and stop at all "," as you can see in my preview post i need to read inbetween "," and put it into a variable, this is the part i dont know how to do.

 

<?php
if(!($_POST['filename'])){
echo '
<form name="form1" method="post" action="import.php">
  File Name: <input type="text" name="filename">
  <input name="submit" type="submit" value="Start">
</form>';
} else {
echo "Processing... Please Wait.";
$file = $_POST['filename'];
$handle = fopen($file, "r");


}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.