我使用 select 语句进行如下查询,它可以成功地获取记录:
$table = new Bugs();
$select = $table->select();
$select->where('bug_status = ?', 'NEW');
$rows = $table->fetchAll($select);
但现在我想更新同一条记录。例如,在简单的MySQL中。
UPDATE TableName Set id='2' WHERE id='1';
如何在Zend中执行上述查询?
谢谢
我使用 select 语句进行如下查询,它可以成功地获取记录:
$table = new Bugs();
$select = $table->select();
$select->where('bug_status = ?', 'NEW');
$rows = $table->fetchAll($select);
但现在我想更新同一条记录。例如,在简单的MySQL中。
UPDATE TableName Set id='2' WHERE id='1';
如何在Zend中执行上述查询?
谢谢
$data = array(
'field1' => 'value1',
'field2' => 'value2'
);
$where = $table->getAdapter()->quoteInto('id = ?', $id)
$table = new Table();
$table->update($data, $where);
既然您已经获取了要更改的行,似乎最简单的方法就是执行:
$row->id = 2;
$row->save();
如果您想增加一列,请使用Zend_Db_Expr 例如:
$table->update(array('views' => new Zend_Db_Expr('views + 1')),$where);
$data = array(
"field1" => "value1",
"field2" => "value2"
);
$where['id = ?'] = $id;
$where['status = ?'] = $status;
$table = new Table();
$table->update($data, $where);
public function updateCampaign($id, $name, $value){
$data = array(
'name' => $name,
'value' => $value,
);
$this->update($data, 'id = ?', $id );
}
$data = array(
"field1" => "value1",
"field2" => "value2"
);
$where = "id = " . $id;
$table = new Table();
$table->update($data, $where);
$where = $table->getAdapter()->quoteInto('id = ?', $id)
的快捷方式获得奖励分数。 - Richard Ayotte