Skip to content

Instantly share code, notes, and snippets.

@trungpv1601
Created July 21, 2017 07:33
Show Gist options
  • Save trungpv1601/ca15a18386f964a537faba174fa065b4 to your computer and use it in GitHub Desktop.
Save trungpv1601/ca15a18386f964a537faba174fa065b4 to your computer and use it in GitHub Desktop.
PHP SQL Server: Call Stored Proceduree PDO MSSQL PARAM OUT
<?php
try
{
$conn = new PDO ("sqlsrv:server=(local);Database=DatabaseName", "user", "password");
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
// Param
$idReturn = 0; // Param Out
$name = 'Name'; // Pram In
$query = "{? = call sp_getIdFromName(?)}";
$stmt = $database->pdo->prepare($query);
$stmt->bindParam(1, $idReturn, PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT, 4);
$stmt->bindParam(2, $name, PDO::PARAM_STR);
$stmt->execute();
echo $idReturn;
}
catch(Exception $e)
{
die( print_r( $e->getMessage() ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment