How to insert multiple record using Doctrine

/**

* Insert multiple record together

* improve speed from 8 seconds to less than 1 second for insert 200 records

*/

$em = $this->_service->getEntityManager();

foreach ($pageIdsNeedAdd as $pageID ){

$rp = newRolePermission;

$rp->pageID = $pageID;

$rp->roleID = $data['roleID'];

$em->persist($rp);

}

$em->flush();

$em->clear();

Leave a Reply

Your email address will not be published. Required fields are marked *