Store Procedure In PHP

1843 0

$1*/ mo hosting! Get going with GoDaddy!

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


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 .

In this article

Join the Conversation