久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      thinkphp如何調(diào)用sqlserver儲(chǔ)存過程返回多個(gè)結(jié)果集

      thinkphp如何調(diào)用sqlserver儲(chǔ)存過程返回多個(gè)結(jié)果集

      首先安裝擴(kuò)展

      windows

      分為兩個(gè)步驟

      1.找到對(duì)應(yīng)自己PHP版本的pdo擴(kuò)展,下載解壓出來,并且在php.ini里面啟用擴(kuò)展,需要注意的問題是php版本以及是否為安全版本

      2.下載 ODBC Driver https://docs.microsoft.com/zh-cn/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-2017,這個(gè)沒啥注意的,你是啥系統(tǒng)就下載啥安裝包就行

      linux 和 windows差不多,安裝擴(kuò)展的話直接可以用pecl

      當(dāng)你成功加載了可以在phpinfo()里面看到,當(dāng)然了,如果你安裝擴(kuò)展這些都有諸多問題都話,~你可真拉稀。

      thinkphp操作sqlsrv儲(chǔ)存過程

      我使用的tp版本是5.0和操作多個(gè)數(shù)據(jù)庫(kù),希望能對(duì)你有所幫助

      配置config文件

       // 賬號(hào)數(shù)據(jù)庫(kù)     'UserDBConn' =>  [         'type'            => 'sqlsrv',         // 服務(wù)器地址         'hostname'        => '139.129.1.1',         // 數(shù)據(jù)庫(kù)名         'database'        => 'DB3',         // 用戶名         'username'        => 'xxxx',         // 密碼         'password'        => 'tt123!@#',         // 端口         'hostport'        => '5188'     ],     // 金幣數(shù)據(jù)庫(kù)     'ScoreDBConn' =>  [         'type'            => 'sqlsrv',         // 服務(wù)器地址         'hostname'        => '139.129.1.1',         // 數(shù)據(jù)庫(kù)名         'database'        => 'DB2',         // 用戶名         'username'        => 'xxxx',         // 密碼         'password'        => 'tt123!@#',         // 端口         'hostport'        => '5188'     ],     // 記錄數(shù)據(jù)庫(kù)     'RecordDBConn' =>  [         'type'            => 'sqlsrv',         // 服務(wù)器地址         'hostname'        => '139.129.1.1',         // 數(shù)據(jù)庫(kù)名         'database'        => 'DB1',         // 用戶名         'username'        => 'xxxx',         // 密碼         'password'        => 'tt123!@#',         // 端口         'hostport'        => '5188'     ],

      修改thinkphp/library/think/Model.php

      在末尾追加

       /**      * @param $DbconnName      */     protected function Dbconn($DbconnName){         try{             $conn = Db::connect($DbconnName);         }catch (InvalidArgumentException $e){             echo '連接異常';             die;         }         return $conn;     }

      添加模型

      Agent.php

      查詢和增刪改都可以調(diào)用query,如果你沒有想要獲取的結(jié)果集的話可以調(diào)用execute()。

      query()有一個(gè)弊端,如果你的綁定參數(shù)的形式(非參數(shù)綁定)是直接寫進(jìn)sql的話,他有可能會(huì)判斷你這個(gè)不是一個(gè)儲(chǔ)存過程;

      具體實(shí)現(xiàn)請(qǐng)查看thinkphp/library/think/db/Connection.php:368行,當(dāng)然也不會(huì)有結(jié)果集返回。

      你也可以用調(diào)用procedure(),這個(gè)方法調(diào)用的話就一定會(huì)返回結(jié)果集。

      起初我就是這個(gè)問題,并沒有采用綁定參數(shù)的形式提交,直接寫sql,就獲取不到結(jié)果集,后來我在我的sql提行里面加入了SET NOCOUNT ON;,才能勉強(qiáng)拿到返回,在文章最后我給出了我最開始獲取的結(jié)果集的方案例子,但是真的拉稀,你們可以看看,不要吐槽。

      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

      很顯然 這里并不會(huì)獲取到@AgentID 以及 @TotalCount;他只會(huì)返回Agent_GetAgentList的結(jié)果集

      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; }

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)