觸發創作只是不工作創建觸發器,我用盡了一切我能想到的,例如,像:如何笨的遷移庫
$this->db->query("DELIMITER //\r\n
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
DELIMITER ;");
而且無論我做什麼,我都將它獲得的感覺不會創建觸發器,因爲Codeigniter只在一行中創建SQL語句。與不換行試過,仍然得到這個消息:
錯誤編號:1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER // CREATE TRIGGER `delete_post` BEFORE DELETE ON `posts` FOR EAC' at line 1
DELIMITER // CREATE TRIGGER `delete_post` BEFORE DELETE ON `posts` FOR EACH ROW BEGIN DELETE FROM page_content WHERE page_content.post_id = OLD.post_id; END // DELIMITER ;
在phpMyAdmin,觸發創建的方式工作,所以SQL是有效
取出分隔符部分,mysql_或mysqli_函數應該能夠執行沒有分隔符的觸發器。 –
我會試試看,因爲它絕對是一個分隔符問題,它需要在我自己的測試行上 – NaturalBornCamper
是的,試試看你也可以檢查這個線程http://stackoverflow.com/questions/3762880/ create-mysql-trigger-via-php –