How to use mysql stored procedures on php

I’ll try to make this short because I have already discussed some essentials on mysql stored procedures here.


  • WAMP Server
  • Heidi SQL
  • Notepad++ or any text editor with line numbers.

I’ll only be discussing how to actually call the stored procedure from your php application, so please read this first if you don’t know how to create stored procedures on heidi sql.

So in your notepad++ open up the php file where your query is.

It should look something like:

$sql="INSERT INTO students(name, course) VALUES('$name', '$course')";

Where the include part is where I inherit from the conn.php file for the mysql connection essentials. The conn.php file could look something like this:

$con=mysql_connect('$host', '$uname', '$pword' );
$sdb=mysql_select_db($con, 'databaseName');

mysql_connect and mysql_select_db are built in methods in php to connect to mysql. Often times the host name is ‘localhost’ and the username is ‘root’. There is no password by default. But I just inputted here ‘secret’ as the password.

Now, if you want to use the stored procedure that you have created. Then just call it from your php file. Just replace the actual sql query with the method call:

$sql="call stored_procedure_name('$name', '$course')";

That’s just an example, the parameters could expand depending on the fields that are on your table. Don’t forget to replace ‘stored_procedure_name’ with the actual name of the stored procedure that you have created in heidi sql.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s