Connecting Tech Pros Worldwide Forums | Help | Site Map

read from file with delimiters

Boris ©avc
Guest
 
Posts: n/a
#1: Jul 17 '05
How do I read data from file with delimiters (for instance A;B;ccc;S45A;UU)?
I'd like to write that data to MYSQL table...

Thanks for the help,
Boris Savc



Jon Kraft
Guest
 
Posts: n/a
#2: Jul 17 '05

re: read from file with delimiters


"Boris ©avc" <boris.savc@odis-info.com> wrote:
[color=blue]
> How do I read data from file with delimiters (for instance
> A;B;ccc;S45A;UU)? I'd like to write that data to MYSQL table...[/color]

Please don't multipost!

PHP:
Have a look into fgetcsv():
http://uk.php.net/manual/en/function.fgetcsv.php

MySQL:
Have a look into LOAD DATA INFILE:
http://www.mysql.com/doc/en/LOAD_DATA.html

HTH;
JOn
John Dunlop
Guest
 
Posts: n/a
#3: Jul 17 '05

re: read from file with delimiters


Boris ©avc wrote:
[color=blue]
> How do I read data from file with delimiters (for instance A;B;ccc;S45A;UU)?[/color]

http://www.php.net/manual/en/function.fgetcsv.php

--
Jock
Fred H
Guest
 
Posts: n/a
#4: Jul 17 '05

re: read from file with delimiters


Pć Tue, 24 Feb 2004 11:27:58 +0100, skrev Boris ©avc
<boris.savc@odis-info.com>:
[color=blue]
> How do I read data from file with delimiters (for instance
> A;B;ccc;S45A;UU)?
> I'd like to write that data to MYSQL table...[/color]

This is -one- way of doing it:

$lines = array(); //Create an array.
$lines = file("my_delimed_data_file.dat");//Load the lines into the array.
foreach($lines as $line) { //Loop through the array.
list($field1,$field2,$field3,$field4,$field5) = explode(";",$line);
//Extract your vars from the line.
mysql_query("INSERT INTO your_table ('field1',___,'field5')
VALUES(".$field1.",___,".$field5.")"); //Insert them into the db.
}//End of loop

The ___ part is of course just "fill in the blanks yourself".
The code is of course not complete, but you get the general idea.


--
Fred H

void FredH::Contact() {
TextToSpeach.say("frode at age dee dee dot en oh");
}
Closed Thread