Created
July 21, 2017 07:33
-
-
Save trungpv1601/ca15a18386f964a537faba174fa065b4 to your computer and use it in GitHub Desktop.
PHP SQL Server: Call Stored Proceduree PDO MSSQL PARAM OUT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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