Issue with simple MySQL Script

41 Views Asked by At

Why is the SQL below Producing the indicated error?

SET @natureRegTime:=7200;
SET @natureTime:=1;

Error it produces is

QueryException
PHP 8.1.2-1ubuntu2.14
10.25.0
SQLSTATE[42000]: Syntax error or access violation: 1064 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 'SET @natureTime:=1' 

I've tried without the colon and get the same result. It doesn't matter what the second line is it throws the same error. I tested it directly in MySQL but do not get the error.

I also tried removing all the comments just leaving the two SET commands but I get the same result.

Any suggestions as to what the issue is?

1

There are 1 best solutions below

5
Alejandro23 On

I think you should declare the variables at the beginning of the script

DECLARE @natureRegTime AS INT, @natureTime AS INT
SET @natureRegTime= 7200
SET @natureTime = 1