title: Return value from MySQL stored procedure
body: <p>So I've finally decided to get around to learning how to use stored procedures, and although I do have them working, I'm unsure if I'm doing it correctly - aka. the <em>best</em> way. So here's what I've got.</p>
  
  <p>Three procedures: TryAddTag, CheckTagExists, and AddTag.</p>
  
  <p>TryAddTag is the procedure that is my intermediary between other code (eg. PHP, etc...) and the other two procedures, so this is the one that gets called.</p>
  
  <p><br />
  <strong>TryAddTag</strong></p>
  
  <pre><code>DELIMITER //
   CREATE PROCEDURE TryAddTag(
    IN tagName VARCHAR(255)
   )
  
   BEGIN
  
   -- Check if tag already exists
   CALL CheckTagExists(tagName, @doesTagExist);
  
   -- If it does not exist, add it
   IF @doesTagExist = FALSE THEN
    CALL AddTag(tagName);
   END IF;
  
  END //
  DELIMITER ;
  </code></pre>
  
  <p><br />
  <strong>AddTag</strong></p>
  
  <pre><code>DELIMITER //
   CREATE PROCEDURE AddTag(
    IN tagName VARCHAR(255)
   )
   BEGIN
  
   INSERT INTO
    tags
   VALUES(
    NULL,
    tagName
   );
  
  END //
  DELIMITER ;
  </code></pre>
  
  <p><br />
  <strong>CheckTagExists</strong></p>
  
  <pre><code>DELIMITER //
   CREATE PROCEDURE CheckTagExists(
    IN
     tagName VARCHAR(255),
    OUT
     doesTagExist BOOL
   )
   BEGIN
  
   -- Check if tag exists
   SELECT
    EXISTS(
     SELECT
      *
     FROM
      tags
     WHERE
      tags.NAME = tagName
    )
   INTO
    doesTagExist;
  
  END //
  DELIMITER ;
  </code></pre>
  
  <p><br />
  My problems stem from this and use of @doesTagExist.</p>
  
  <pre><code>-- Check if tag already exists
  CALL CheckTagExists(tagName, @doesTagExist);
  </code></pre>
  
  <p>Is the the correct way to use one of these variables? And/or, how can I use a DECLARE'd variable to store the result of CheckTagExists within TryAddTag? I expected something along the lines of</p>
  
  <pre><code>...
  DECLARE doesTagExist BOOL;
  SET doesTagExist = CheckTagExist('str');
  ...
  </code></pre>
  
  <p>or something like that...</p>