I have collections of clients, and every collection can contain many clients. This PHP code loops collections, and clients inside every collection. And saves the client to the database.
foreach ($collections as $key => $collection) {
foreach ($collection as $k => $client) {
$name = $client['name'];
//...
$clientObj = new Client();
$clientObj->setName($name);
//..
$clientObj->save();
}
}
What I want to do, is to group every collection in one Mysql query, then go to the next collection. Because the previous code executes one query per client, And for performance, we need one query per collection.
How can we do that?