我尝试在codeigniter中实现数据库触发器,我想在其他特定表上插入操作后更新一个特定的表。我正在尝试以下代码,但它对我不起作用。
这是我在模型中写的功能:
<?php
public function enter_follower($follower_id, $following_id) {
$data = array('follower_user' => $follower_id,
'following_user' => $following_id
);
$this->db->insert('followers', $data);
//return $this->db->insert_id();
$this->db->query("
CREATE TRIGGER `UpdateFollower` AFTER INSERT ON followers
FOR EACH ROW
UPDATE business_users SET followerCount = followerCount + 1 WHERE user_id = $following_id
END");
if ($this->affected_rows() > 0) {
return true
} else {
return false
}
} ?>