Creating a procedure in mySql with parameters

Peter Rasmussen picture Peter Rasmussen · Feb 18, 2011 · Viewed 126.8k times · Source

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

Peter Rasmussen picture Peter Rasmussen · Feb 18, 2011

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.