How to Call a Stored Procedure in PHP

I’m new to PHP. One of the first things I wanted to figure out was how to call a stored procedure in PHP. After some research, I found that the following works. I’m not sure if it’s the best way to do it, so if anyone has some better tips, please comment. (This example is passing the username and password from a form post into a stored procedure.)

define(‘CLIENT_MULTI_RESULTS’, 131072);

$conn = mysql_connect(“hostname”, “username”, “password”, 1 , CLIENT_MULTI_RESULTS)
or die(mysql_error());

mysql_select_db(“datasource”) or die(mysql_error());

$user = $_POST["Username"];
$pass = $_POST["Password"];
$query = mysql_query(“call MyProce(‘$user’,'$pass’)”) or die( mysql_error() );

if (mysql_numrows($query) != 0){
echo ‘query returned results’;
}
else {
echo ‘query returned no results’;
}

Leave a Reply