Symfony 1.4改进了doctrine save()方法 [英] Symfony 1.4 improve doctrine save() method

查看:127
本文介绍了Symfony 1.4改进了doctrine save()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有500个条目。在我的后台我有动作。例如:

  public function executeMyAction(sfWebRequest $ request){

//获取一些数据table
$ templates = Doctrine_Core :: getTable('SeoTemplates') - > findOneByEntity('training');

//从其他表获取数据(500项)
$ trainings = Doctrine :: getTable('Training') - > getTraining();

//对数据进行一些操作
foreach($ trainings as $ training){

$ training-> setSomeValue1('some_data');
$ training-> setSomeValue2('some_data');
$ training-> setSomeValue2('some_data');

}

//问题部分(尝试保存)
$ trainings-> save();
}

save()执行了很长时间。如何解决这个问题?



在我的问题部分我已经知道所有错误致命错误:中超过30秒的最大执行时间

解决方案

保存每个记录而不是一个集合

  $ templates = Doctrine_Core :: getTable('SeoTemplates') - > findOneByEntity('training'); 
$ trainings = Doctrine :: getTable('Training') - > getTraining();
foreach($ trainings as $ training){
$ training-> setSomeValue1('some_data');
$ training-> setSomeValue2('some_data');
$ training-> setSomeValue2('some_data');
$ training-> save();
}

或使用Doctrine使用查询更新记录

  $ q = Doctrine_Query :: create()
- > update('TABLE')
- > set($ val1,'?',$ val1)
- > set($ val2,'?',$ val2)
- > set($ val3,'?',$ val3)
- > where('id =?',$ id)
- > execute();


I have 500 entries in my db. In my backend I have action. For example:

 public function executeMyAction(sfWebRequest $request) {

 // Get some data from table
 $templates = Doctrine_Core::getTable('SeoTemplates')->findOneByEntity('training');

//Get data from other table(500 items)
 $trainings = Doctrine::getTable('Training')->getTraining();

  // Make some operations with data
  foreach ($trainings as $training) {

       $training->setSomeValue1('some_data');
       $training->setSomeValue2('some_data');
       $training->setSomeValue2('some_data');

  }

// Problem part (try to save)
$trainings->save();
}

save() performed for a long time. How to solve this problem? Is it possible?

In my problem part I have all known error Fatal error: Maximum execution time of 30 seconds exceeded in

解决方案

Save each record instead of a collection

$templates = Doctrine_Core::getTable('SeoTemplates')->findOneByEntity('training');
$trainings = Doctrine::getTable('Training')->getTraining();
foreach ($trainings as $training) {
   $training->setSomeValue1('some_data');
   $training->setSomeValue2('some_data');
   $training->setSomeValue2('some_data');
   $training->save();
}

or use Doctrine to update the records using a query

$q = Doctrine_Query::create()
   ->update('TABLE')
   ->set($val1, '?', $val1)
   ->set($val2, '?', $val2)
   ->set($val3, '?', $val3)
   ->where('id = ?', $id)
   ->execute();

这篇关于Symfony 1.4改进了doctrine save()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆