A
A
Anastasia2021-07-25 16:36:03
MySQL
Anastasia, 2021-07-25 16:36:03

Which is better: individual SELECT queries or grouping them?

There is an array:

$person = ['Петров Александр 10.10.1990', 'Иванов Владимир 09.08.1995', 'Силанова Ольга 01.12.1980']

In my database for each of the people there is detailed information. The person column looks like this: Alexander Petrov 10/10/1990 , and in the result column just add. infa.
I need to find out if the data on a third-party service has changed relative to mine. I reassemble this array with people and make a request to a third-party api. In response, I receive a huge array, where just in the same order as my original array is a description of each person.
Next, I have to compare the data with those in the database and those that I received. And here I have a question: in fact, I can iterate over $person and do a SELECT into the base, whereperson = $person[$i];, but very often the result value can be null for me and therefore the comparison will be very fast, therefore the next query will immediately occur in the database, and I will do a big load on the database. Maybe it's worth grouping queries and immediately getting the entire array from the database, and then comparing them by brute force?

And if grouping is better, then tell me how to organize it if:
1. I get my $person array from the database (meaning, it is not constant and I need to generate a query in the database on the fly)
2. I use PDO and a regular query For one person it looks like this:
$pdoGet = $pdo->prepare("SELECT result,id FROM data WHERE person = ? ORDER BY id DESC");
$pdoGet->execute([$pers]);
$frombd_strstr = $pdoGet->fetch();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Peter Slobodyanyuk, 2021-07-25
@PeterLS

It is better to group, since it also takes time to connect to the mysql server.
Moreover, if the result values ​​are not large and your mysql server supports working with JSON, then it is better to compare directly in the query ( working with JSON ).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question