11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

www.it-ebooks.infoCHAPTER 32 • STORED ROUTINESproductid, an IN parameter that determines the product you’re interested in, and count, an OUTparameter that returns the value back to the caller’s scope:CREATE PROCEDURE get_inventory(IN product CHAR(8), OUT count INT)SELECT 45 INTO count;`This procedure can then be called like soCALL get_inventory("ZXY83393", @count);and the count parameter can be accessed like soSELECT @count;CharacteristicsSeveral attributes known as characteristics allow you to tweak the stored procedure’s behavior. Thecomplete range of characteristics is presented below, followed by an introduction to each:LANGUAGE SQL| [NOT] DETERMINISTIC| { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }| SQL SECURITY {DEFINER | INVOKER}| COMMENT 'string'LANGUAGE SQLAt present, SQL is the only supported stored procedure language, but there are plans to introduce aframework for supporting other languages in the future. This framework will be made public, meaningany willing and able programmer will be free to add support for his favorite language. For example, it’squite likely that you’ll be able to create stored procedures using languages such as <strong>PHP</strong>, Perl, andPython, meaning the capabilities of the procedures will be limited only by the boundaries of thelanguage being used.[NOT] DETERMINISTICOnly used with stored functions, any function declared as DETERMINISTIC will return the same valueevery time, provided the same set of parameters is passed in. Declaring a function DETERMINISTIC helps<strong>MySQL</strong> optimize execution of the stored function and aids in replication scenarios.CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATAThis setting indicates what type of task the stored procedure will do. The default, CONTAINS SQL, specifiesthat SQL is present but will not read or write data. NO SQL indicates that no SQL is present in theprocedure. READS SQL DATA indicates that the SQL will only retrieve data. Finally, MODIFIES SQL DATAindicates that the SQL will modify data. At the time of writing, this characteristic had no bearing on whatthe stored procedure was capable of doing.631

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!