我正在尝试使用 Zend_Db 进行与此类似的更新:
UPDATE `TABLE` SET
column = column + 'new value'
WHERE
foo = 'bar'
你们中有人曾经这样做过吗?是否可以? 谢谢
最佳答案
在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!')
));
关于database - ZF Db 附加到列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10900418/