How to create triggers in Codeigniter's migration library

后端 未结 1 1124
失恋的感觉
失恋的感觉 2021-01-20 14:14

Triggers creation are just not working, I tried everything I can think of, for instance, like that:

$this->db->query(\"DELIMITER //\\r\\n
CREATE TRIGGE         


        
1条回答
  •  温柔的废话
    2021-01-20 15:01

    You should remove the delimiter from the trigger while executing via PHP. mysql_ or mysqli_ functions should be able to execute the trigger without the delimiter.

    Here is how to do it.

    $this->db->query("
    CREATE TRIGGER `delete_post` BEFORE DELETE ON `posts`\r\n
    FOR EACH ROW BEGIN\r\n
    DELETE FROM page_content WHERE page_content.post_id = OLD.post_id;\r\n
    END\r\n
    //\r\n
    ");
    

    0 讨论(0)
提交回复
热议问题