2011-06-05 35 views
2

我的表在MySQL:的symfony 1.4學說1.2 - 創建用戶友好的查詢/更新

id | num1 | num2| num 3| num3| num5| 
1 | 6 | 3 | 4 | 2 | 1 | 

在SQL我,例如做:

$num = num2; 
$val = 2; 
$id = 2; 

$sql = "update TABLE set '$num'='$val' where id='$id'"; 
mysql_query($sql); 

我可以$val$id做,但我與$num有問題...

如何在Doctrine 1.2中做到這一點?

回答

11

嘗試這樣:

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