I have created a data-structure in Mysql with table name(CSV filename) and field names(CSV column names).
Right now I am importing the data from csv to Mysql table successfully Where as I am hard-coding csv file name and field name in script. How to dynamical fetch bec I have manny csv files to import into mysql.
<?php
include "db.php";
$filename = "C:\REQ\Status.csv";
if (($handle = fopen($filename, 'r')) !== FALSE)
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
print_r($data);
$import="INSERT into status(status) values('$data[1]')";
mysql_query($import) or die(mysql_error());
}
fclose($handle);
?>
I have implement this code and it is tested code. I think it is very use full
You have follow some rule:-
1.your csv file according to database table name (ex: db table name is users then csv should be users.csv)
2.Your csv file’s first row should be db table fields name (ex: Id, name etc) after the start your data entry
3.you can download data source class from :- http://code.google.com/p/php-csv-parser/
because i have require below the code: require_once ‘CSV/DataSource.php’;