How to execute a MySQL 5.0 stored procedure using PHP

Can someone please tell me what I need installed and some sample code of how to execute a mySQL stored procedure with parameters using PHP.
Kobz46Asked:
Who is Participating?
 
Aleksandar BradarićSoftware DeveloperCommented:
It's basic stuff, but yes, you are right - you have to use `mysqli` as the old extension does not support the new 4.1/5.x stuff:
---
  $data = mysqli_connect($my_server, $my_username, $my_password, $my_database, $my_port);
  if(!empty($data)) {
    $query = mysqli_query($data, 'CALL yourProc(1, 2)');
    mysqli_close($data);
  }
---
0
 
Aleksandar BradarićSoftware DeveloperCommented:
Nothing special - same as for executing a SELECT or UPDATE statement. Just use:
---
CALL procedureName(param1, param2)
---
0
 
Kobz46Author Commented:
Can you post some sample code of how you would implement it? Would be of great help! Thanks leannonn.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
Kobz46Author Commented:
Also, what mySQL extension are you using? mySQL or mySQLi?
0
 
Kobz46Author Commented:
Ok, that helps. Sorry for sounding stupid, I'm currently migrating from ASP/SQL to PHP/mySQL so i'm quite the newby.

Seems like I will have to sort out mySQLi extension first. I have installed it, its specified in my php.ini file, but it still tells me "Call to undefined function: mysqli_connect() in...". Once sorted, will the following code to the trick to, for example, write all the email addresses from the stored proc to screen?
-----
$data = mysqli_connect("localhost","sa","koffie","jump_products");
if(!empty($data)) {
$query = mysqli_query($data, 'CALL sp_AdminUsersGet()');
while($row = @mysql_fetch_array($query))
{
      echo $row["EmailAddress"];
}
mysqli_close($data);
}
-----
If not, how would this be done. I'm really wrecking my brain, but want to seriously learn php and mySQL. Your help and patience is appreciated. Im upping the point value.
0
 
Aleksandar BradarićSoftware DeveloperCommented:
> Call to undefined function: mysqli_connect()

Have you installed the `mysqli` extension? See here: http://dev.mysql.com/downloads/connector/php/

> @mysql_fetch_array($query))

This will have to be `mysqli_fetch_array`, but it should work. You might have to change the `echo` line to:
---
echo $row[0];
---
0
 
Kobz46Author Commented:
Thanks leannonn, I sorted out the mysqli problem ,and your code works wonders. Thanks a lot!
0
 
Aleksandar BradarićSoftware DeveloperCommented:
I'm glad I could help :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.