Return true from a stored procedure

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
raydona
Forum Newbie
Posts: 21
Joined: Sat Mar 21, 2009 9:17 am

Return true from a stored procedure

Post 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.
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: Return true from a stored procedure

Post 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.
Post Reply