D
D
Daniel2016-07-11 15:32:34
PHP
Daniel, 2016-07-11 15:32:34

PHP+SQL. How not to use database queries in a loop?

Good to everyone!
There is a constantly updated array with records. Data is added from this array to the database. It is necessary that each record in the array is checked for presence in the database. It turns out that when iterating over the array in each iteration, you need to make a request to the database? Is it possible in another way?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2016-07-11
@Valtasaar

UNIQUE + INSERT IGNORE

M
Maxim Fedorov, 2016-07-11
@qonand

If you just need to add many records: Use INSERT IGNORE + bulk insert, like so:
well, do not forget about the indexes, and if the database is especially large, I recommend doing partitioning

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question