Skip to content

Instantly share code, notes, and snippets.

@trungpv1601
Last active August 9, 2017 03:46
Show Gist options
  • Save trungpv1601/9996621dc35dd2d6ef324a600c821573 to your computer and use it in GitHub Desktop.
Save trungpv1601/9996621dc35dd2d6ef324a600c821573 to your computer and use it in GitHub Desktop.
Problem Call Store Procedure PDO with MS SQL

If you are using a stored procedure then use

SET NOCOUNT ON 

The problem is that the stored procedure returns a result containing the number of rows affected as the first result.

$NULL = NULL;
$a = 1;
$b = "";
$query = "SET NOCOUNT ON;exec spABC ?, ?, ?;";
$stmt = $this->database->pdo->prepare($query, array(PDO::SQLSRV_ATTR_DIRECT_QUERY => true));

$stmt->bindParam(1, $a, PDO::PARAM_INT); 
$stmt->bindParam(2, $NULL, PDO::PARAM_NULL); 
$stmt->bindParam(3, $b, PDO::PARAM_STR); 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment