如何在 Zend 中更新数据库表记录?

发布于 2024-10-01 00:03:24 字数 328 浏览 6 评论 0原文

我正在使用这样的选择,它成功获取记录:

$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 中执行上述查询?

谢谢

I am using select like this and it is fetching record successfully:

$table = new Bugs();
$select = $table->select();
$select->where('bug_status = ?', 'NEW');
$rows = $table->fetchAll($select);

But Now I want to update same record. For example in simple MySQL.

UPDATE TableName Set id='2' WHERE id='1';

How to execute above query in Zend ?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

木緿 2024-10-08 00:03:24
$data = array(
   'field1' => 'value1',
   'field2' => 'value2'
);
$where = $table->getAdapter()->quoteInto('id = ?', $id)

$table = new Table();

$table->update($data, $where);
$data = array(
   'field1' => 'value1',
   'field2' => 'value2'
);
$where = $table->getAdapter()->quoteInto('id = ?', $id)

$table = new Table();

$table->update($data, $where);
不必了 2024-10-08 00:03:24

由于您已经获取了要更改的行,因此似乎最简单的做法是:

$row->id = 2;
$row->save();

Since you're already fetching the row you want to change, it seems simplest to just do:

$row->id = 2;
$row->save();
天赋异禀 2024-10-08 00:03:24

以防万一你想增加一列使用 Zend_Db_Expr
例如:

$table->update(array('views' => new Zend_Db_Expr('views + 1')),$where);

just in case you wanna increment a column use Zend_Db_Expr
eg:

$table->update(array('views' => new Zend_Db_Expr('views + 1')),$where);
卷耳 2024-10-08 00:03:24

对于多个 where 语句,请使用以下内容。

$data = array(
    "field1" => "value1",
    "field2" => "value2"
);
$where['id = ?'] = $id;
$where['status = ?'] = $status;

$table = new Table();

$table->update($data, $where);

For more than one where statement use the following.

$data = array(
    "field1" => "value1",
    "field2" => "value2"
);
$where['id = ?'] = $id;
$where['status = ?'] = $status;

$table = new Table();

$table->update($data, $where);
ゝ杯具 2024-10-08 00:03:24
public function updateCampaign($id, $name, $value){
    $data = array(
        'name' => $name,
        'value' => $value,
    );
    $this->update($data, 'id = ?', $id );
}
public function updateCampaign($id, $name, $value){
    $data = array(
        'name' => $name,
        'value' => $value,
    );
    $this->update($data, 'id = ?', $id );
}
少女七分熟 2024-10-08 00:03:24
   $data = array(
    "field1" => "value1",
    "field2" => "value2"
);

$where = "id = " . $id;

$table = new Table();

$table->update($data, $where);
   $data = array(
    "field1" => "value1",
    "field2" => "value2"
);

$where = "id = " . $id;

$table = new Table();

$table->update($data, $where);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文