我想用Zend Framework编写以下SQL更新查询:
UPDATE my_table
SET my_field
WHERE name = 'John'
AND (other_field = 'foo' OR other_field = 'bar')
如何使用Zend Framework执行此操作?
答案 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();