Voting

: min(five, eight)?
(Example: nine)

The Note You're Voting On

matt at bigbadweb dot co dot uk
10 years ago
Example of how to formally specify the params, AND get output.
<?php

// Setup connection
$serverName = "serverName\sqlexpress";
$connectionInfo = array( "Database"=>"dbName", "UID"=>"username", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if(
$conn === false) {
die(
print_r( sqlsrv_errors(), true));
}

// specify params - MUST be a variable that can be passed by reference!
$myparams['Item_ID'] = intval(-2);
$myparams['Item_Name'] = "Foo";

// Set up the proc params array - be sure to pass the param by reference
$procedure_params = array(
array(&
$myparams['Item_ID'], SQLSRV_PARAM_OUT),
array(&
$myparams['Item_Name'], SQLSRV_PARAM_OUT)
);

// EXEC the procedure, {call stp_Create_Item (@Item_ID = ?, @Item_Name = ?)} seems to fail with various errors in my experiments
$sql = "EXEC stp_Create_Item @Item_ID = ?, @Item_Name = ?";

$stmt = sqlsrv_prepare($conn, $sql, $procedure_params);

if( !
$stmt ) {
die(
print_r( sqlsrv_errors(), true));
}

if(
sqlsrv_execute($stmt)){
while(
$res = sqlsrv_next_result($stmt)){
// make sure all result sets are stepped through, since the output params may not be set until this happens
}
// Output params are now set,
print_r($params);
print_r($myparams);
}else{
die(
print_r( sqlsrv_errors(), true));
}
?>

<< Back to user notes page

To Top