Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.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/9/loops/2.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 将sql查询转换为Fluentpdo查询_Php_Mysql_Fluentpdo - Fatal编程技术网

Php 将sql查询转换为Fluentpdo查询

Php 将sql查询转换为Fluentpdo查询,php,mysql,fluentpdo,Php,Mysql,Fluentpdo,我用php编写了以下sql查询: $query = sprintf("UPDATE bank_info SET amount_dollar = amount_dollar +'$amount_dollar' , amount_euro = amount_euro + '$amount_euro' , amount_local = amount_local + '$

我用php编写了以下sql查询:

$query = sprintf("UPDATE bank_info SET
                      amount_dollar = amount_dollar +'$amount_dollar'  ,
                      amount_euro = amount_euro + '$amount_euro' ,
                      amount_local = amount_local + '$amount_local'
                      WHERE bank_id = '$bank_id' ");
此查询工作正常,但我想使用FluentPDO转换此查询。 我想使用数组来设置值。 例如:

$table='bank_info'; //table name
$arrVal=array();    //values needs to be SET
$arrVal['amount_dollar = amount_dollar+?']=$amount_dollar;
$arrVal['amount_euro = amount_euro+?']=$amount_euro;
$arrVal['amount_local = amount_local+?']=$amount_local;
$arrWhere=array();  //where condition
$arrWhere['bank_id']=$bank_id;
以下是查询:

$query = $this->pdo->update($table)->set($arrVal)->where($arrWhere);

$query->execute();
我认为问题出在$arrVal中,找不到正确的方法来设置表中某列的当前值并向其添加值。
我多次使用数组从DB/表中选择和获取值,因此我认为$arrhere不是问题所在

嗯,找到了答案

例如:

这对我有用:

$id = 5;
$field = 'stock';
$amount = 1;

$increment = array($field => new FluentLiteral($field.' + '.$amount));

$fpdo->update('products')->set($increment)->where('id', $id)->execute();