0

I am trying to create a trigger into mySQL using PHP

mysqli_select_db($host, "game");
$sql = "CREATE TRIGGER test_seven BEFORE INSERT ON test FOR EACH ROW INSERT INTO test (name) VALUES ('test')";
$query = $host->prepare($sql);
$query->execute();

And it is not working even though I tried running it on phpMyAdmin and it worked.

EDIT: "This command is not supported in the prepared statement protocol yet" Is there a way of skipping the prepare statement then ?

8
  • I also faced the same issue , for procedures / tiggers, still dont know why it does not allow, but my guess is , its due to user rights, in phpmyadmin user has diffrent rights/ privelges and when you do some thing with code it has diffrent priveleges, even though the user are same. Not sure if its correct or not Commented Feb 5, 2018 at 12:29
  • "not working" means what? What error do you get? Are you even checking for mySQL errors in your PHP code? Does the user which PHP is logging in with have rights to do this? Commented Feb 5, 2018 at 13:04
  • @ADyson "This command is not supported in the prepared statement protocol yet" Is there a way of skipping the prepare statement then ? Commented Feb 5, 2018 at 13:11
  • stackoverflow.com/questions/3762880/… Commented Feb 5, 2018 at 13:12
  • 1
    Don't execute it as prepared statement. This is an admins job, not a programmers. But apart from that, I doubt that the statement worked, like you say. Your trigger would create an infinite loop and is therefore not allowed. Your insert statement would fire the trigger, which would fire the trigger, which would fire the trigger...and so on. Commented Feb 5, 2018 at 13:16

1 Answer 1

1

Apparently the real problem was the fact that I was not supposed to use the PDO::prepare statement, if anyone else is having this issue use PDO::exec.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.