写一个更新查询,其中ID是X,名称是zf中的foo或bar

时间:2011-12-02 09:05:30

标签: sql zend-framework

我想用Zend Framework编写以下SQL更新查询:

UPDATE my_table
SET my_field
WHERE name = 'John'
AND (other_field = 'foo' OR other_field = 'bar')

如何使用Zend Framework执行此操作?

1 个答案:

答案 0 :(得分:0)

假设您有my_table的模型文件..如果没有在模型目录中创建一个。

 <?php  

  class Yournamespace_Model_Mytable extends Zend_Db_Table_Abstract{

            protected $_name = "my_table";
        public function updateFunction(){
           $data = array('my_field' => 'new value to be set');
           $where[] = 'name = John';
           $where[] = '(other_field = "foo" OR other_field = "bar")';       
                $update= $this->update($data, $where);        

        }

        }

只需拨打任何此类动作

$obj = new Yournamespace_Model_Mytable();
$obj->updateFunction();