我嘗試進行通用更新/交換,這將始終切換活動狀態。在SQL中很簡單:帶交換值表達式的zend框架更新
UPDATE contacts SET active = ABS(active - 1) WHERE id = ....
其中活動是小int /標誌0或1,所以它始終工作。
當我嘗試實現它來模擬類擴展Zend_Db_Table類:
public function disableContact($contact_id)
{
$where = $this->getAdapter()->quoteInto('id = ?', $contact_id);
$data = Array();
$data ['active'] = '(ABS(the.contacts.active - 1))';
return parent::update($data, $where);
}
我Error: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "(ABS(the.contacts.active - 1))"<p><pre>#0 ......./ZendFramework-1.11.0/library/Zend/Db/Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)
如何通過ABS表達更新?
+1。 'ABS'在這裏是不必要的:'1 - the.contacts.active'將返回你需要的東西 – zerkms
Zend_Db_Expr完美工作 - 謝謝。 '1-active'也是一個好主意 - 謝謝 – bensiu