June 22, 2012 4:03 pm

Mysql Stored Procedure in PHP

Are you making stored procedures if not please have a look at this. Stored procedures can help to improve web applications and reduce database requests traffic. This post explains you how to make procedures and decrease database requests.


users table contains username and name.

Result.php (Direct database server access)

Calling SQL statements directly. Here displaying the users content with PHP.

I had implemented Stored Procedure at huzoorbux.com

How to Create Stored Procedure
You can create stored procedures that run on your database server. Stored Procedure name userIDName(). Just like SQL statements.

How to Call Stored Procedure

Results.php (With stored procedures)

Stored Procedure Input

Simple Way
insert procedure IN – Input , name and datatype.

 Nice Way

I suggest you to create stored procedures with following statements.


Here inserting values into users table with calling insert() procedure.

 DataBase.php Database configuration code.


Author Huzoor Bux

I am Huzoor Bux from Karachi (Pakistan). I have been working as a PHP Developer from last 5+ years, and its my passion to learn new things and implement them as a practice. Basically I am a PHP developer but now days exploring more in HTML5, CSS and jQuery libraries.

Tutorial Categories:
  • can’t call multiple stored procedure.

  • ex
    include('DataBase.php'); // Check code below of the post.

    sql=mysql_query("SELECT userID,name FROM users");
    echo $row['user'].'–'.$row['name'].'’;

    $sql=mysql_query(“SELECT userID,name FROM users2″);
    echo $row[‘user’].’–‘.$row[‘name’].”;

  • moses

    how can i write a unit test case for this

  • nonu

    don’t copy to 9lessons.info

    • huzoorbux

      🙂 What is the copy of 9lessons?

  • mohicanin

    you made procedure userIDName() and then you call it using mysql_query(“CALL users()”)….
    srsly is it to hard to make such simple tutorial without such ridiculous mistakes?

    • huzoorbux

      I saw this in php manual they also called it in query if you have any better way please suggest me.

  • julie

    how about delete and update by ID?

  • adar

    userid or username, wkwkwk

  • Jyo

    wht’s this??

  • Rasmi Ranjan Swain

    Can you show the example with mysqli instead of mysql

  • Deep

    CREATE PROCEDURE insert(IN userID INT,IN name VARCHAR(40))
    in this line can you please let me know , what is meaning of ‘ IN ‘

  • nani

    hii a this a simple code

    but when i run it it is giving as Resource id#3