Save CSV files into mysql database

前端 未结 3 1480
旧时难觅i
旧时难觅i 2020-12-05 22:44

I have a lot of csv files in a directory. With these files, I have to write a script that put their content in the right fields and tables of my database. I am almost beginn

3条回答
  •  无人及你
    2020-12-05 23:04

    after

    foreach ($row as $field) {
    echo $field . '
    ';

    You need to parse the result after ; like:

    $pieces = explode(";", $field);
    

    and then insert every piece into the database

    $sql = ' INSERT INTO X VALUES ("'.$pieces[0].'","'.$pieces[1].'","'.$pieces[2].'","'.$pieces[3].'","'.$pieces[4].'")';
    mysql_query($sql, $conn);
    

提交回复
热议问题