Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

read csv file and insert into mysql

Status
Not open for further replies.

hisham

IS-IT--Management
Nov 6, 2000
194
Any one can help me to creat a code that read csv file and insert into mysql.
Thanks in advance.
 
Instead of doing it through PHP, I recommend using MySQL's LOAD DATA command.

______________________________________________________________________
TANSTAAFL!
 
but the users will update the data using csv, and they haven't telnet or any access to Mysql server, so i will create a php file to let them do that.
Thanks.
 
nothing more simple :)

just do this:

$file=implode("",file("file.csv"));
while(list(,$line)=each($file)){
$query="INSERT INTO table VALUES ($line);
mysql_query($query);
}

I assumed the data had the quotes when needed. If it doesn't have, you have to do first:
$fields=explode(",",$line);

and then you have the first field in $fields[0], the second in $fields[1] and so on until N field is in $fields[N-1]

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top