470,848 Members | 1,307 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,848 developers. It's quick & easy.

read from file with delimiters

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
Jul 17 '05 #1
3 2090
"Boris ©avc" <bo********@odis-info.com> wrote:
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...


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
Jul 17 '05 #2
Boris ©avc wrote:
How do I read data from file with delimiters (for instance A;B;ccc;S45A;UU)?


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

--
Jock
Jul 17 '05 #3
Pć Tue, 24 Feb 2004 11:27:58 +0100, skrev Boris ©avc
<bo********@odis-info.com>:
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...


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");
}
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jong Choi | last post: by
2 posts views Thread by les_ander | last post: by
75 posts views Thread by Greg McIntyre | last post: by
39 posts views Thread by Timex | last post: by
2 posts views Thread by Profetas | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.