2010-03-15

[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

2 則留言:

  1. hello... hapi blogging... have a nice day! just visiting here....

    回覆刪除

你好!歡迎你在我的 Blog 上留下你寶貴的意見。