Codeigniter:触发器无法更新表'tb_berita'

时间:2019-09-12 13:40:10

标签: php mysql codeigniter

我对使用触发器进行更新存在一些问题。 我有这样的功能更新表中的列:

控制器

public function updateStatus()
    {
        $id_berita = $this->input->post('id_berita');
        $object = ["status_berita" => "true"];
        $updateStatus = $this->berita->updateStatusBerita($object, $id_berita);
        if ($updateStatus) {
            echo "berhasil";
        } else {
            echo "gagal";
        }
    }

型号

public function updateStatusBerita($object, $id_berita)
    {
        $this->db->where('id_berita', $id_berita);
        return $this->db->update('tb_berita', $object);
    }

触发器

CREATE TRIGGER updateHeadlineBerita AFTER UPDATE ON tb_berita FOR EACH ROW BEGIN UPDATE tb_berita SET NEW.status_berita='false' WHERE NEW.status_berita='true' AND NEW.status_berita <>NEW.id_berita; End;

当我调用函数updateStatus时出现错误:

A Database Error Occurred
Error Number: 1442

Can't update table 'tb_berita' in stored function/trigger because it is already used by statement which invoked this stored function/trigger

UPDATE `tb_berita` SET `status_berita` = 'true' WHERE `id_berita` = '12'

Filename: C:/xampp/htdocs/flutter-news/system/database/DB_driver.php

Line Number: 691

我知道其他人已经在问这个问题,但是我没有解决我的错误。

能帮我吗?

0 个答案:

没有答案