dou7466 2012-06-28 14:38 采纳率: 0%
浏览 59
已采纳

为什么我不能用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.

Here is my code

$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();

Evaluating $error returns this error message:

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?

  • 写回答

2条回答 默认 最新

  • dongxie45083 2012-06-28 14:43
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?