thinkphp调用sqlserver储存过程返回多个结果集(2)

class Agent extends Model
{
  public $Dbname = 'UserDBConn';
  public function GetIndirectAgentList($agentId,$strAccount,$strSuperior,$iPageIndex,$pagesize)
  {
    $conn = $this->Dbconn($this->Dbname);
    try{
      $TotalCount = 0;
      $res = $conn::query('exec [dbo].[Agent_GetAgentList] :agentId,:strAccount,:strSuperior,:iPageIndex,:pagesize,:TotalCount', [
        'agentId' => $agentId,
        'strAccount' => [$strAccount, PDO::PARAM_STR],
        'strSuperior' => [$strSuperior, PDO::PARAM_STR],
        'iPageIndex' => [$iPageIndex, PDO::PARAM_INT],
        'pagesize' => [$pagesize, PDO::PARAM_INT],
        'TotalCount' => [$TotalCount, PDO::PARAM_INPUT_OUTPUT],
      ]);
    }catch (PDOException $e)
    {
      return false;
    }
    return $res;
  }
}

最初的Agent.php

很显然 这里并不会获取到@AgentID 以及 @TotalCount;他只会返回Agent_GetAgentList的结果集

public function GetIndirectAgentList($agentId,$strAccount,$strSuperior,$iPageIndex,$pagesize)
  {
    $conn = $this->Dbconn($this->Dbname);
    try{

      $res = $conn->query('
        SET NOCOUNT ON;
        declare @AgentID int;
        declare @TotalCount int;
        exec [dbo].[Agent_GetAgentList] '.$agentId.',\''.$strAccount.'\',\''.$strSuperior.'\','.$iPageIndex.','.$pagesize.',@TotalCount output;
        select @AgentID as AgentID,@TotalCount as TotalCount
        ');
    }catch (PDOException $e)
    {
      return false;
    }
    return $res;
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持黑区网络。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/3804.html