0

Ive been working with symfony since few days, now I am trying to make updates, but I am stuck with many problems, one of them is that I cant find a way to update a field adding a value, instead replacing the value, I just want to add the new one.

$q = Doctrine_Query::create()
->update('OhrmBudget')
->set('spent', 'spend' + $cost)
->where('month', $month)
->where('year', $year);
$q->execute();

I feel like the "wheres" are not working! because I also have another update and it sets the new value to all fields on my table.

$q = Doctrine_Query::create()
->update('OhrmTrainningSubmit')
->set('state', $state)
->where('trainning', $training)
->andWhere('user', $user);
$q->execute();

Any idea how to make this updates? I checked a link with reference I checked, but in none of them make this kind of updates, and none of them use more than one Where that I need, anyone could give me an idea?

I am with symfony 1.4

Thanks

4

1 回答 1

2

我认为对于您的第一个查询,它会更好:

$q = Doctrine_Query::create()
->update('OhrmBudget b')
->set('b.spent', 'newvalue')
->where('b.month = ?', $month)
->andWhere('b.year = ?', $year)
->execute();

您必须使用“ andWhere() ”而不是“where()”作为第二个 where。

于 2013-04-16T17:52:21.253 回答