PHP SQL Server Stored Procedure

Sayed Ahmed
Nov 29 · 1 min read
/* prepare the statement resource */
$stmt=mssql_init("your_stored_procedure", $conn);

/* now bind the parameters to it */
mssql_bind($stmt, "@id", $id, SQLINT4, FALSE);
mssql_bind($stmt, "@name", $name, SQLVARCHAR, FALSE);
mssql_bind($stmt, "@email", $email, SQLVARCHAR, FALSE);

/* now execute the procedure */
$result = mssql_execute($stmt);

Another Example

$conn = mssql_connect($db_host,$db_user,$db_password);if ($conn===false){
echo 'Cannot connect.';
exit;
}

if (mssql_select_db("YourDatabase",$conn) === false) {
echo 'no database';
exit;
}

$proc = mssql_init('YourStoredProcedure',$conn);
mssql_bind($proc,'@ParameterOne',$ParameterOne,SQLVARCHAR);
mssql_bind($proc,'@ParameterTwo',$ParameterTwo,SQLVARCHAR);
mssql_bind($proc,'@ParameterThree',$ParameterThree,SQLVARCHAR);
if ($result = mssql_execute($proc)) {
if ($row = mssql_fetch_row($result)){
// process results
}
}
Sayed Ahmed

Written by

Software Engineer, Data Scientist, Machine Learning Engineer.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade