1

I am trying to add a MySQL stored procedure to the database on plugin install in Craft 3. I currently have an install migration calling a function from the safeUp method. In this function I am using Craft::$app->getDb()->createCommand(" DELIMITER $$ CREATE PROCEDURE ...")->execute(). However this does not seem to do the trick.

4
  • Does the user account Craft is connecting to the database with have CREATE ROUTINE permissions? Craft doesn't require them by default.
    – Brad Bell
    Feb 16 '18 at 19:18
  • Also worth mentioning that PostgreSQL has different syntax if you'll be supporting that.
    – Brad Bell
    Feb 16 '18 at 19:19
  • The user does have Create Routine Permissions. The log says there is a syntax error however I have checked the syntax and tested it via SQLPro and it runs. We will start out with MYSQL support until we can convert sql to PostgreSQL.
    – aran
    Feb 16 '18 at 19:46
  • It says the syntax error is on the first line with the DELIMITER $$.
    – aran
    Feb 16 '18 at 20:30
1

After further investigation Yii handles the DELIMITER ;; in the createCommand() method. I just had to remove the opening and closing DELIMITER syntax and execute the Craft::$app->getDb()->createCommand("CREATE PROCEDURE ( ... )")->execute() for it to install.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.