Peter Rasmussen Peter Rasmussen - 4 months ago 7
MySQL Question

Creating a procedure in mySql with parameters

I am trying to make a stored procedure using mySQL. This procedure will validate a username and a password. I'm currently running mySQL 5.0.32 so it should be possible to create procedures.

Heres the code I've used. All I get is an SQL syntax error.

GO
CREATE PROCEDURE checkUser
(IN @brugernavn varchar(64)),IN @password varchar(64))
BEGIN
SELECT COUNT(*) FROM bruger WHERE bruger.brugernavn=@brugernavn AND bruger.pass=@Password;
END;


Thank you in advance

Answer

I figured it out now. Here's the correct answer

CREATE PROCEDURE checkUser 
(
   brugernavn1 varchar(64),
   password varchar(64)
) 
BEGIN 
   SELECT COUNT(*) FROM bruger 
   WHERE bruger.brugernavn=brugernavn1 
   AND bruger.pass=password; 
END; 

@ points to a global var in mysql. The above syntax is correct.

Comments