Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uploading csv file into mysql through php

Tags:

php

mysql

csv

i know how to upload a csv file into mysql database but only through cmd. i want to know how to upload csv file into mysql database using php form and will disregard some information on the excel and will only start importing starting from a certain line. ? kindly help me.

like image 720
freeloader Avatar asked Jul 04 '26 14:07

freeloader


1 Answers

(PHP 4, PHP 5)

fgetcsv

See php manual http://php.net/manual/en/function.fgetcsv.php

<?php
$row = 1;
if (($handle = fopen("test.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        echo "<p> $num fields in line $row: <br /></p>\n";
        $row++;
        for ($c=0; $c < $num; $c++) {
            echo $data[$c] . "<br />\n";
        }
    }
    fclose($handle);
}
?>
like image 131
Rinto George Avatar answered Jul 07 '26 04:07

Rinto George