How to remove or avoid inserting column headers when importing a separated value file into a database using PHP?

后端 未结 3 1071
轻奢々
轻奢々 2021-01-24 09:42

I have semicolon-separated .dat file and I want to read that file and store its contents into a database.

Structure of .dat file:



        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-24 10:17

    Enforce inserting only on the right datatype.

    if(is_numeric($data[0])){ ... your code ... }

    More correctly, you should be enforcing that the columns don't allow insertion of bad data at the database level, so your listed columns should be of integer type since they're ids, not of whatever type they are currently (varchar, perhaps). And you could then handle errors appropriately, e.g. by ignoring and discarding inappropriate data.

提交回复
热议问题