2010-03-15 21:28

[PHP] 利用 mysqli 建立 MySQL Trigger

<?php 
$dbAdapter = new mysqli('host', 'user', 'pass', 'db');

$sql = "
DROP TRIGGER IF EXISTS `table_insert_trigger`;

CREATE TRIGGER `table_insert_trigger` BEFORE INSERT ON `table`
FOR EACH ROW 
    SET NEW.`CreateDate`=NOW();
";

$dbAdapter->multi_query($sql);

就是這麼簡單,為什麼都沒有人寫文章,害我找好久!囧

參考文章:
How To Use Triggers to Track Changes in MySQL
MySQL / PHPMyAdmin Trigger Syntax