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 回應:

林佳男 (Germos Onner) 提到...

您好, 謝謝您的文章.

Hapi 提到...

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