Check out if MySQL built-in LOAD DATA INFILE
statement doesn't fit for you.
If not, you can use PHP SplFileObject
class to iterate over your files lines without loading all them into memory. It have specific methods to parse lines like that, like SplFileObject::fgetcsv()
and SplFileObject::fscanf()
. In this case you might want to be using PDO
to have a MySQL transaction to commit all insert statements at once to speed up the import proccess or rollback all them if something goes wrong.