views:

167

answers:

1

Hi

I wonder how i can import csv files that selected by user to database using php.

is there any practical way on this ?

thanks

+2  A: 

PHP has a function for this: fgetcsv(). You'll still have to write the loop and the code that inserts rows into the database however.

$in = fopen('filename.csv', 'r');
while (($row = fgetcsv($in, 10000, ',')) !== false) {
  mysql_query("INSERT INTO ....");
}
fclose($in);
cletus
yeah but how can i use it to selected file by user, i guess i need to upload file first then use this function then delete file ?
Ahmet vardar
Use PHP's support for uploading files. See http://www.tizag.com/phpT/fileupload.php and other tutorials.
cletus
ok got it ! thx
Ahmet vardar