Save 20 users with one SQL query?

I save such a user in the doctrine:

$user = User(); $user->name = 'peter'; $user->save(); 

Is there a way to keep 20 users in a single sql query?

or do I need to loop the above code 20 times, thereby creating 20 sql queries?

thanks

+4
source share
2 answers

You can add $user objects to Doctrine_Collection and then call $collection->save() , which basically does a loop for you.

+7
source

From your point of view, as a user of Doctrine, you work with objects and should not be interested in SQL queries.

If you have 20 different users, you must have 20 different objects - this means, yes, 20 requests (or more, depending on what your objects do) to save them.

+2
source

Source: https://habr.com/ru/post/1309240/


All Articles