Jeyakumar
Jeyakumar

Reputation: 39

How to change mysql delimiter through php

I created an event with a set of sql statements in mysql terminal, It is working fine. But I want to create this event from php script. My query is below.

DELIMITER |

CREATE EVENT e_cart

ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 3 MINUTE

DO

BEGIN

SET @var_orderid = '';

SET @var_orderid = (SELECT orderid FROM order WHERE id=308);

IF @var_orderid = NULL THEN

UPDATE order SET status=1 WHERE id=308;

END IF;
END |

DELIMITER ;

This results in :-

Error : 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 'DELIMITER | CREATE EVENT e_cart ON SCHEDULE AT CUR' at line 1

How do I execute this event from php script?

Upvotes: 3

Views: 2870

Answers (1)

matt
matt

Reputation: 4734

DELIMITER isn't MySQL server command but MySQL CLI/Query Browser/Workbench etc. It only says when to send command to MySQL server.

Omit DELIMITER and send whole CREATE EVENT statement as one command, it should work.

Upvotes: 7

Related Questions