php: importing multiple csv files into mysql table

前端 未结 2 1125
终归单人心
终归单人心 2021-01-15 19:37


        
相关标签:
2条回答
  • 2021-01-15 19:51

    If you want to import several csv files and you're doing it manually, you might also want to use a graphical tool to make the job easier. You can use Adminer for this:

    1. Access adminer from your browser.
    2. Log in with admin rights.
    3. Select your database.
    4. Click on the Import option on the left.
    5. Choose your .csv file.
    6. Press the Execute button.
    0 讨论(0)
  • 2021-01-15 20:08

    If your file is actually a csv file with fields separated by comma, you must specify the field separator.

    LOAD DATA INFILE '$file' INTO TABLE $tbl_name FIELDS TERMINATED BY ','
    

    If you don't state the field separator mysql considers the field separator as tab (\t).

    In case the file is created with return carriage, monstly windows applications do that, you also need to add in the end of the statement:

    LINES TERMINATED BY '\r\n'
    
    0 讨论(0)
提交回复
热议问题