我有客户的集合,每个集合可以包含许多客户。该PHP代码循环了集合,每个集合中都有客户端。并将客户端保存到数据库。
foreach ($collections as $key => $collection) {
foreach ($collection as $k => $client) {
$name = $client['name'];
//...
$clientObj = new Client();
$clientObj->setName($name);
//..
$clientObj->save();
}
}
我想要做的是将每个集合分组在一个Mysql查询中,然后转到下一个集合。因为前面的代码对每个客户端执行一个查询,并且为了提高性能,我们需要对每个集合执行一个查询。
我们该怎么做?
将每个记录添加到对集合对象Doctrine_Collection
的调用save()
。
* Saves all records of this collection and processes the * difference of the last snapshot and the current data
例如:
$collection = new Doctrine_Collection('client');
$collection->add($client1);
$collection->add($client2);
$collection->save();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句