I want to read .csv file in PHP and put its contents into the database. I wrote the following code:
$row = 1;
$file = fopen("qryWebsite.csv", "r");
while (($data = fgetcsv($file, 8000, ",")) !== FALSE) {
$num = count($data);
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "\n";}}
fclose($file);
I do not get any error but it does not show me result.
You can try the below code. It works perfect for me. I have comment to make it more understandable. You can take reference from this code.
One liner to parse a CSV file into an array