欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP調(diào)用MsSQL Server 2012存儲(chǔ)過(guò)程獲取多結(jié)果集(包含output參數(shù))的詳解

 更新時(shí)間:2013年07月03日 10:38:56   作者:  
本篇文章是對(duì)PHP調(diào)用MsSQL Server 2012存儲(chǔ)過(guò)程獲取多結(jié)果集(包含output參數(shù))的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
【PHP Source Code】:
復(fù)制代碼 代碼如下:

$dbh = new PDO('sqlsrv:server=連接地址;Database=數(shù)據(jù)庫(kù)名', 用戶(hù)名, 密碼);
try {
 $procName = "P_Test_GetMixData";
 $stmt = $dbh->prepare("EXEC $procName ?, ?, ?");
 $nReturnValue = 0;
 $strReturnValue = "";
 $strSearchValue = "abandonship";
 $stmt->bindParam(1, $nReturnValue, PDO::PARAM_INT | PDO::PARAM_INPUT_OUTPUT, PDO::SQLSRV_PARAM_OUT_DEFAULT_SIZE);
 $stmt->bindParam(2, $strReturnValue, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 10);
 $stmt->bindParam(3, $strSearchValue , PDO::PARAM_STR);
 $stmt->execute();

 //獲取第一個(gè)結(jié)果集.
 $rowset_1 = $stmt->fetch(PDO::FETCH_ASSOC);
 print_r($rowset_1);
 echo '<br><br>';

 //獲取第二個(gè)結(jié)果集.
 $stmt->nextRowset();
 $rowset_2 = $stmt->fetch();
 print_r($rowset_2);
 echo '<br><br>';
 $stmt->nextRowset();
 // 獲取兩個(gè)輸出類(lèi)型的參數(shù)
 echo $nReturnValue.'<br><br>';
 echo $strReturnValue;
} catch (Exception $e) {
 echo $e->getMessage();
}

【SQL PROCEDURE】:
復(fù)制代碼 代碼如下:

/**
* 用于測(cè)試PDO調(diào)用MsSQLServer2012存儲(chǔ)過(guò)程獲取復(fù)合結(jié)果集Demo
* Code CreateBy abandonship 2012.10.11
**/
CREATE PROCEDURE [dbo].[P_Test_GetMixData](
 @Message_1 tinyint output,
 @Messgae_2 varchar(10) output,
 @SearchValue varchar(50)
) As
set nocount on

 set @Message_1 = 123
 set @Messgae_2 = 'Hi,there!This is abandonship!'
 select * from _T1 where col1 like '%'+@SearchValue+'%'
 select * from _T2 where col1 like '%'+@SearchValue+'%'
set nocount off

【一些要注意的問(wèn)題】:當(dāng)bindParam中存在需要輸出類(lèi)型的參數(shù)時(shí),必須包含長(zhǎng)度($length)。
【備注】:$length: An optional (integer) length of the data type. You can specify PDO::SQLSRV_PARAM_OUT_DEFAULT_SIZE to indicate the default size when using PDO::PARAM_INT or PDO::PARAM_BOOL in $data_type.

相關(guān)文章

最新評(píng)論