Database Reference
In-Depth Information
Entering the procedure
We then enter the procedure's code in the main query box:
CREATE PROCEDURE `add_page`(IN param_isbn VARCHAR(25), IN param_pages
INT, OUT param_message VARCHAR(100))
BEGIN
IF param_pages > 100 THEN
SET param_message = 'the number of pages is too big';
ELSE
UPDATE book SET page_count = page_count + param_pages WHERE
isbn=param_isbn;
SET param_message = 'success';
END IF;
END
//
On clicking Go , we get a success message if the syntax is correct. If it is not, well, it's
time to revise our typing abilities or debug our syntax. Unfortunately, MySQL does
not come with a procedure debugger.
Testing the procedure
Again, in the query box, we test our procedure by entering the following statements.
Here, we are using an SQL variable, @message , which will receive the contents of the
OUT parameter param_message :
call add_page('1-234567-22-0', 4, @message);
SELECT @message;
We can then verify whether the page count for this topic has increased. We also need
to test the problematic case:
call add_page('1-234567-22-0', 101, @message);
SELECT @message;
This procedure is now available for calling from PHP, using the mysqli extension.
 
Search WWH ::




Custom Search