Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php symfony条令更新查询中的计算_Php_Sql_Symfony1_Doctrine - Fatal编程技术网

Php symfony条令更新查询中的计算

Php symfony条令更新查询中的计算,php,sql,symfony1,doctrine,Php,Sql,Symfony1,Doctrine,我们有一种情况,我们需要根据表中的现有数据更新记录,这是我手动创建的查询,只是为了解释这个查询使用金额字段减去其51%的值来更新奖金字段数据 update users set final_amount = amount-(amount*51/100) where id = 1 这是我的symfony代码 $q = Doctrine_Query::create() ->update('Users') ->set('fina

我们有一种情况,我们需要根据表中的现有数据更新记录,这是我手动创建的查询,只是为了解释这个查询使用金额字段减去其51%的值来更新奖金字段数据

update users set final_amount = amount-(amount*51/100) where id = 1
这是我的symfony代码

$q = Doctrine_Query::create()           
   ->update('Users')              
   ->set('final_amount',"'". $amount."'") 
   ->where('id =1')->execute();

我希望我做对了。这很简单:

$query = Doctrine_Query::create()
           ->update('Users')
           ->set('final_amount', $amount - $amount * 51 / 100)
           ->where('id = 1')
           ->execute();

这很容易做到,甚至有例子

DQL解析器是智能的enouth,用于检测集合部分中的列


顺便说一下,不要使用
->where('id=1')
,而是
->where('id=?',1)

我认为
金额
是一个表列,而不是一个变量。但问题并不准确:(
$q = Doctrine_Query::create()
    ->update('users')
    ->set('final_amount', 'amount-(amount*51/100)')
    ->where('id = ?', 1)->execute();