Hi all,
>I would like to import csv file into mysql database. While im working on the testing database, no data from csv is display. Is it because of my comma seperated error? Could anyone take a look at my code? Many thanks to you all.
>Here is my csv file content:
“name”,“userid”,“pwd”,“date”
“john_smith”,“js”,“5621”,“june12”
“jane_doe”,“jd”,“8894”,“sept12”
>Here is my coding structure, assuming database is included:
$file = “testdb.csv”;
$fp = fopen($file, “r”);
$data = fread($fp, filesize($file));
fclose($fp);
$output = str_replace("’,’", “”, $data);
$output = explode("
“, $output);
foreach($output as $var) {
$tmp = explode(”’,’", $var);
$name = $tmp[0];
$userid = $tmp[1];
$pwd = $tmp[2];
$date = $tmp[4];
$sql = “INSERT INTO table SET name=’$name’,userid=’$userid’, pwd=’$pwd’, date=’$date’”;
mysql_query($sql);
}
echo “Done!”;