我尝试使用Zend_Db进行类似的更新:
UPDATE `TABLE` SET
column = column + 'new value'
WHERE
foo = 'bar'
你们之前有没有这样做过?可能吗? 感谢
答案 0 :(得分:2)
在Zend_Db_Expr的帮助下,这是可能的。
示例:
$newValue = 101;
$data = array('column' =>
new Zend_Db_Expr($db->quoteInto('column + ?', $newValue)));
$where = $db->quoteInto('foo = ?', 'bar');
$updated = $db->update('TABLE', $data, $where);
结果查询:
UPDATE `TABLE` SET `column` = `column` + 101 WHERE `foo` = 'bar';
如果您询问如何附加字符串,则代码类似,但在处理字符数据时不能使用+
运算符,而是使用CONCAT()。
例如,将$data
数组更改为:
$data = array('varcharCol' =>
new Zend_Db_Expr(
$db->quoteInto('CONCAT(varcharCol, ?)', ' append more text!')
));