Page 1 of 1

Return true from a stored procedure

Posted: Tue Mar 24, 2009 10:27 am
by raydona
Hi, I have never created a stored procedure so please bear with me. I wish to create a stored procedure where if a condition is met true is returned, else false is returned, something like:
CREATE PROCEDURE SomeName(IN X VARCHAR(15), IN Y VARCHAR(30))
BEGIN
SELECT A, B
FROM Table
//Go through table and
IF A == X AND B == Y return true, else return false
END;

How can I achieve this? Further, how can I display the bool result in the statement:
$res = mysql_query("call SomeName($textA, $textB)");
if (!mysql_query($res,$con))
{ die('Error: ' . mysql_error());
}
I will be grateful for all help.

Re: Return true from a stored procedure

Posted: Wed Apr 01, 2009 1:08 am
by novice4eva
I would recommend going for a stored function rather than stored procedure, although you can make procedure do the same thing but you should know the procedure don't return(you could set in out parameter and get the data using bind functions). Then it is a simple select statement like select functionName(function arguments) as returnValue from dual.

Also you cannot do normal selects inside stored functions and procedures, it should be SELECT .. INTO...FROM...WHERE..., but i think there is set command in mysql..i am not sure.