Created
April 3, 2013 00:05
-
-
Save jehoshua02/5297332 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// instantiate pdo | |
$pdo = new PDO("mysql:host=localhost;dbname=test", 'root', 'root'); | |
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); | |
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
// create trigger | |
$sql = <<<SQL | |
DROP TRIGGER IF EXISTS table1InsertTrigger; | |
DELIMITER $$ | |
CREATE TRIGGER table1InsertTrigger | |
AFTER INSERT ON table1 | |
FOR EACH ROW | |
BEGIN | |
INSERT INTO table2 SET field1 = new.field1; | |
END; | |
$$ | |
DELIMITER ; | |
SQL; | |
$pdoStatement = $pdo->prepare($sql); | |
$pdoStatement->execute(); | |
// verify | |
$pdoStatement = $pdo->prepare("SHOW TRIGGERS WHERE `Trigger` = 'table1InsertTrigger'"); | |
$pdoStatement->execute(); | |
print_r($pdoStatement->fetch()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment