Zend Framework SQL更新查询
问题描述:
我该如何编写这个SQL Zend Framework的方式?Zend Framework SQL更新查询
UPDATE register
SET balance = (balance + 10)
WHERE added_date > 1259944184 ;
我在Zend的网站或网上找不到任何这方面的例子。
我需要使用“Zend_Db_Expr
”吗?
答
acording到Zend的framwork文档
使用本
$data = array(
'balance' => 'balance + 10'
);
$n = $db->update('register ', $data, 'added_date > 1259944184');
答
这为我工作:
$data = array(balance => new Zend_DB_Expr('balance + 10'));
$db->update('register ', $data, 'added_date > 1259944184');
答
试试这个...确保您的模型已准备就绪。
$table = new register();
这是模型类
balance=balance+10;
$data = array(
'balance' => 'balance'
);
$where = $table->getAdapter()->quoteInto('added_date > '. 1259944184);
我用这其中[]多个条件
$table->update($data, $where);
答
修改元素为顶部,你可以使用$。 代码如下从表类延伸Zend_Db_Table_Abstract:
$data = array('i_order' => new Zend_DB_Expr('i_order + 1'));
return $this->getAdapter()->update($this->_name, $data, "i_id != {$oCurrent->i_id} AND i_order < {$i_order}");
这并不适用于我。我得到它使用这样的SQL查询: $ stmt = $ this - > _ db-> query('UPDATE'。$ this - > _ name。'SET balance =(balance + \''。$ difference。'\ ')WHERE added_date> \''。$ addedDate。'\''); \t \t $ numAdded = $ stmt-> rowCount(); \t \t echo'
'。$ numAdded。'受影响的行'; 但我真的很想使用ZF的流体方法。 – EricP 2009-12-04 22:18:44