In this post i will explain how to create store procedure in mysql and how to call store procedure in PHP for select, insert, update and delete data from mysql table. A stored procedure has a header and a body using to declarative SQL statements stored inside the database catalog.

There are three different ways to pass parameters in store procedures in mysql:
1) IN-parameters
2) OUT-parameters
3) IN OUT-parameters

Database table

First create user table with id, name and email fields in your test database with mysql. Open phpmyadmin and go to the SQL tabs. Now copy paste below code and execute this query. After successfully execution of below query users table will be created in your selected database.

create-table-in-mysql

how to create store procedure in mysql

Now again go to the SQL tab in phpmyadmin and copy paste below code, then execute query. Now you have created a stored procedure named “UserInfo” which will select all rows from users tables.

Create config.php file

Create config.php file for configure database connection with your mysql database. Add below code in your config.php file and save.

how call store procedure in php code

Create index.php file and copy paste below code and save it. In below code first include config.php to connect your PHP code with mysql database, then call your procedure by using call UserInfo().

how to insert data using stored procedure

Insert.php page

After above steps now create insert.php file and copy paste below code. Now go to your web browser and run the insert.php page. After insert.php page runed value inserted in users table.

Thanks for giving you valuable time on Freewebmentor community. Do like & share with you friends using social media if you liked.