A
A
astrotrain2016-01-30 12:02:25
PHP
astrotrain, 2016-01-30 12:02:25

How to insert very many INSERT at one time from lines in a file (php)?

The bottom line is this: the script dumps either lines or ready-made expressions into a text file, then the script-insert-to- db parses the file and either takes commands from there or generates an insert based on text lines. The question, in fact, is this - how to correctly arrange multiple inserts in the database in order to get it as quickly as possible? Files can be up to ~5 mb, so the load will be quite good. What options should be included with insert and how to correctly form a query? In one insert, for example, you can make several records at once of the type INSERT INTO tbl_name (a, b, c) VALUES (1,2,3), (4,5,6), (7,8,9); , for what is the maximum/optimum amount? Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimonchik, 2016-01-30
@astrotrain

and load data infile is not suitable?

M
Melkij, 2016-01-30
@melkij

Generate CSV and feed via LOAD DATA INFILE directly to the database.
If it doesn't work with load data, then in one transaction you feed multiple inserts (how multiple - see max_allowed_packet)
5 MB of data is not so much.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question