?
Solved

How to execute a MySQL 5.0 stored procedure using PHP

Posted on 2007-08-07
8
Medium Priority
?
275 Views
Last Modified: 2013-12-12
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.
0
Comment
Question by:Kobz46
  • 4
  • 4
8 Comments
 
LVL 17

Expert Comment

by:Aleksandar Bradarić
ID: 19646397
Nothing special - same as for executing a SELECT or UPDATE statement. Just use:
---
CALL procedureName(param1, param2)
---
0
 

Author Comment

by:Kobz46
ID: 19649850
Can you post some sample code of how you would implement it? Would be of great help! Thanks leannonn.
0
 

Author Comment

by:Kobz46
ID: 19651884
Also, what mySQL extension are you using? mySQL or mySQLi?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 17

Accepted Solution

by:
Aleksandar Bradarić earned 1200 total points
ID: 19652102
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
 

Author Comment

by:Kobz46
ID: 19652171
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
 
LVL 17

Expert Comment

by:Aleksandar Bradarić
ID: 19652206
> 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
 

Author Comment

by:Kobz46
ID: 19653001
Thanks leannonn, I sorted out the mysqli problem ,and your code works wonders. Thanks a lot!
0
 
LVL 17

Expert Comment

by:Aleksandar Bradarić
ID: 19653047
I'm glad I could help :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question