| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2009-12-22 22:09 UTC] david dot wright at opticsplanet dot com
 Description:
------------
I cannot retrieve an output parameter from a stored procedure (in my case on SQL Server 2005--am using PDO_DBLIB.
Reproduce code:
---------------
PHP Code:
---------------------------------------------------
/** SNIP. Set up a valid $db here! **/
$return_value = 999;
$sth = $db->prepare("EXEC dbo.opsp_Test ?");
$sth->bindParam(1, $return_value, PDO::PARAM_STR |
PDO::PARAM_INPUT_OUTPUT, 4);
$sth->execute();
echo "$return_value\n";
Stored Procedure
--------------------------------------------------
CREATE PROCEDURE opsp_Test 
	@TheOutputValue int OUTPUT
AS
BEGIN
	SET @TheOutputValue = 11
END
Expected result:
----------------
output should be: 11
Actual result:
--------------
Output is 999 ($return_value unchanged)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 11:00:01 2025 UTC | 
I am experiencing the same issue with PHP 7.0.3, pdo_dblib and MSSQL 2008. Unfortunately I am having to resort to pdo_dblib due to the removal of mssql* functions. Here is my code: $db = new PDO('dblib:host=myhost:1433;dbname=mydb', 'username', 'password'); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "EXEC Stock_Level @myId=:myId, @StockLevel=:StockLevel"; $stmt = $db->prepare($sql); $var = '12345'; $var2 = null; $stmt->bindParam(":myId", $var, PDO::PARAM_STR); $stmt->bindParam(":StockLevel", $var2, PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT); if(!$stmt->execute()) { echo "\nPDO::errorCode(): ", $stmt->errorCode(); } echo "var 2 = " . $var2 . PHP_EOL; This is a big problem!DBLIB on unix cant accesses variables. Changing to windows or sqlsrv with the same code, works. I have a big client running procedure and i need to ge the return LOL <?php $database = ""; $server = ""; $user = ""; $pass=""; $str_host = "dblib:host=" . $server; $str_host .= ";dbname=" . $database; try { $con = new PDO($str_host, $user, $pass); $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $con->exec("SET NOCOUNT ON"); } catch (Exception $ex) { print_r('Error: ' . $ex->getMessage()); exit; } $comando = "DECLARE @mensagem varchar(20); SET @mensagem = 'Diogo Toscano'; SELECT @mensagem;"; $sth = $con->query($comando); foreach ($sth as $row) { echo "<pre>"; print_r ($row); }Expected result: ---------------- Array ( [] => Diogo Toscano [0] => Diogo Toscano ) Actual result: --------------