I've Googled but come up with nothing that I can get my head around.
Are the performance gains from using stored procedures significant?
Would I still want to use prepared statements in conjunction with stored procs or is it generally a one or the other thing?
Can I create stored procs through PHPMyAdmin and manage them from there as well?
What would a stored procedure look like for something simple like this-
SELECT * FROM table a 
INNER JOIN otherTable b 
ON a.join_id=b.join_id 
WHERE someVar = :boundParam
and how would the PHP work (PDO) to call it and bind its parameter?
 
                        
A procedure:
can have zero or more SQL statements with BEGIN ... END statement. *No statement without
BEGIN ... ENDstatement gets error.can have only single statement without
BEGIN ... ENDstatement not changing the delimiter to$$without error.can have multiple parameters with
IN,OUTandINOUTand without them.can get zero or more values with zero or more
INandINOUTparameters from the caller.can return zero or more values to the caller with
OUTandINOUTparameters.can have local variables and user-defined variables. *My answer explains local variables and user-defined variables.
can have transaction.
cannot have RETURN statement otherwise there is the error.
is not atomic by default so if there is error, it is not rollbacked automatically. *My answer explains it in detail.
*In this answer, I explain how to create a procedure with an
INparameter and my answer and my answer explainOUTandINOUTparameters respectively and the doc explains a procedure in detail.For example, you create
testtable as shown below:Then, you insert the row whose
numis2as shown below:Now, you can create
addition(IN value INT)procedure which addsvaluetonumas shown below. *TheINparameterIN value INTcan get the value from the caller and you can also usevalue INTwithoutINwhich is also recognized as anINparameter and basically, you need to change the default delimiter;to something like$$when creating a procedure otherwise there is error, then after creating a procedure, you need to change the delimiter$$back to;as shown below and my answer explains delimiter and you must select a database when creating a procedure otherwise there is the error:Then, you can call
addition(3)with CALL statement, then3is added tonumas shown below:Or, you can set the user-defined session variable e.g.
@vwith3, then3is added tonumas shown below. *The initial value of a user-defined session variable isNULL:In addition, you can create
addition()procedure with the user-defined session variable e.g.@vand without anINparameter as shown below:Then, you set
@vwith3and calladdition(), then3is added tonumas shown below:And, in this case below, you can create
addition(IN value INT)procedure not changing the delimiter to$$without error: