为什么我不能使用PDO创建触发器? [英] Why can't I create a trigger with PDO?

查看:98
本文介绍了为什么我不能使用PDO创建触发器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使触发过程自动化,这样我就不必为要使用的每个表手动创建触发器.不幸的是,我收到一条错误消息,说存在语法错误.

I am trying to automate my trigger process so that I don't have to manually create triggers for every table I want to use. Unfortunately, I get an error back saying there is a syntax error.

这是我的代码

$updateTrigger = "DROP TRIGGER IF EXISTS {$table}Update
    CREATE TRIGGER {$table}Update AFTER UPDATE ON $table
    FOR EACH ROW
    BEGIN
       DECLARE N DATETIME;
       SET N = now();
       INSERT INTO StagesHistory (Stage, StageID, Date, Action)
       VALUES ('$table', NEW.ID, N, ?);
    END";

$ut = $dbh->prepare($updateTrigger);
$ut->execute(array($update));
$error = $ut->errorInfo();

评估$error返回此错误消息:

您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在'CREATE TRIGGER TranslationUpdate之后使用. 第2行的每个R'

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 'CREATE TRIGGER TranslationUpdate AFTER UPDATE ON Translation FOR EACH R' at line 2

我不知道它在说什么错误.有什么问题,我该如何解决?

I can't figure out what error it's talking about. What's the problem, and how do I fix it?

推荐答案

DROP TRIGGER ...CREATE TRIGGER ...是两个单独的语句.您至少需要用;分隔它们,可能在单独的查询中执行它们.

DROP TRIGGER ... and CREATE TRIGGER ... are two separate statements. You need to at least separate them with a ;, possibly execute them in separate queries.

这篇关于为什么我不能使用PDO创建触发器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆