Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Beginners' guide to stored procedures with MySQL?

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?

like image 947
bcmcfc Avatar asked Nov 25 '10 15:11

bcmcfc


People also ask

How do I create a simple stored procedure in MySQL?

Create a simple stored procedure. DELIMITER ; To create the MySQL Stored Procedure, open the MySQL workbench Connect to the MySQL Database copy-paste the code in the query editor window click on Execute. You can view the procedure under stored procedures.

How do you write a stored procedure in SQL for beginners?

A stored procedure is a prepared SQL code that you can save, so the code can be reused over and over again. So if you have an SQL query that you write over and over again, save it as a stored procedure, and then just call it to execute it.

Can we use stored procedure in MySQL?

Answer: MySQL has STORED PROCEDURES that are stored as a part of the database/schema like other entities as tables, indexes, etc. These can be created using CREATE PROCEDURE command and can have optional parameters specified to pass data as well as obtain results as a result of procedure execution.

Where procedures are stored in MySQL?

Where are stored procedures stored? Stored procedures are stored in the mysql. routines and mysql. parameters tables, which are part of the data dictionary.


1 Answers

Consider this a gentle introduction to stored procedures in MySQL: http://www.mysqltutorial.org/mysql-stored-procedure-tutorial.aspx

You sure can create/manage stored procedures in phpMyAdmin.

like image 112
bcosca Avatar answered Sep 27 '22 03:09

bcosca