Store Procedure In PHP

A stored procedure is a set of SQL commands that has been compiled and stored on the  database  server.
Once the stored procedure has been “stored”, client applications can execute the stored procedure over and over again without sending it to the database server again and without compiling it  again.
Stored procedures improve performance by reducing network  traffic and CPU  load.

Comparison with dynamic SQL

  • Remove overhead
  • Avoidance of network  traffic
  • Encapsulation of business  logic
  • Delegation of access-rights
  • Some protection from SQL injection attacks

How To Create And Execute SP

There are various options that can be used to create stored procedures.  In these next few topics we will discuss creating a   stored procedure  and How to execute.

Syntax –

How to insert Data into Database Using Stored Procedure

Create a Sql Table with name user. Structure of the user table given below….

Now create a database connection

Create a stored Procedure with name insertuser.

Argument Modes
IN : Data Values comes in form the calling process and is not changed.
OUT : No Data Value comes in form the calling process; on normal exit, value of argument is passed back to caller.
IN OUT : Data Values comes in form the calling process, and another value is returned on normal exit.

Now create a HTML form (Index.php)

Now execute the store Procedure. Put this on the top of the index Page

View Demo

How to run demo on localhost
First download the zip package. Extract  the zip file  and paste the file in root directory. Now create a database name with test and import the sql file available inside the package. Create a store procedure available inside the package copy .

Download Source Code(Store Procedure In PHP)
Size: 1.84 KB
Version: V 1.0

About the author

Anuj kumar

I'm Anuj kumar a web developer with 4+ year experience .I write blogs in my free time. I love to learn new technologies and share with others. I founded PHPGurukul in September 2015. The main aim of this website to is provide php , jquery , mysql , phpoops and other web development tutorials. I am trying best effort to make PHPGurukul useful for every single moment spend on this website. If you think this website is useful to visit please share with your friend and buddies.

Leave a Comment

Subscribe For Latest Updates