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

php執(zhí)行多個(gè)存儲(chǔ)過程的方法【基于thinkPHP】

 更新時(shí)間:2016年11月08日 11:04:43   作者:ifeixiang  
這篇文章主要介紹了php執(zhí)行多個(gè)存儲(chǔ)過程的方法,結(jié)合實(shí)例形式分析了基于thinkPHP框架調(diào)用多個(gè)存儲(chǔ)過程的相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了php執(zhí)行多個(gè)存儲(chǔ)過程的方法。分享給大家供大家參考,具體如下:

從以前的使用原生代碼來看,只需要將結(jié)果集關(guān)閉即可,即

$this -> queryID -> close();

使用mysqli方式,修改DbMysqli.class.php,將query函數(shù)改為:

public function query($str) {
    $this -> initConnect(false);
    if (!$this -> _linkID) {
      return false;
    }
    $this -> queryStr = $str;
    //釋放前次的查詢結(jié)果
    if ($this -> queryID)
      $this -> free();
    N('db_query', 1);
    // 記錄開始執(zhí)行時(shí)間
    G('queryStartTime');
    $this -> queryID = $this -> _linkID -> query($str);
    // 對存儲(chǔ)過程改進(jìn)
    $ret = array();
    $this -> debug();
    if (false === $this -> queryID) {
      $this -> error();
      return false;
    } else {
      $this -> numRows = $this -> queryID -> num_rows;
      $this -> numCols = $this -> queryID -> field_count;
      $ret = $this -> getAll();
    }
    //主要將這段移動(dòng)了一下,關(guān)閉結(jié)果集
    if ($this -> _linkID -> more_results()) {
      while (($res = $this -> _linkID -> next_result()) != NULL) {
        $this -> queryID -> close();
      }
    }
    return $ret ;
}

下面就可以調(diào)用多個(gè)存儲(chǔ)過程,或許執(zhí)行其他SQL操作,可以直接使用M函數(shù)

在使用thinkphp的時(shí)候發(fā)現(xiàn)執(zhí)行多個(gè)存儲(chǔ)過程只能執(zhí)行第一個(gè),看了一下源碼Driver/Db/DbMysql.class,已經(jīng)對存儲(chǔ)過程進(jìn)行了一定處理,但是不知道為什么運(yùn)行不了。

用原生代碼解決了問題(下面是部分代碼):

$db = new mysqli(C("DB_HOST"), C("DB_USER"), C("DB_PWD"), C("DB_NAME"));
if (mysqli_connect_errno())
throw_exception(mysqli_connect_error());
$t2 = microtime(true);
echo "數(shù)據(jù)庫連接用時(shí):" . (($t2 - $t1)) . "s <br />";
$arr = array();
// 1st Query
$procedure = "call p1()";
$result = $db->query($procedure);
if ($result) {
// Cycle through results
while ($row = $result->fetch_object()) {
//添加到對象數(shù)組
$arr[] = $row;
}
// 這里是最重要的,需要將游標(biāo)移動(dòng)下一個(gè)結(jié)果集
$result->close();
$db->next_result();
}
$procedure = "call p2()";
$result = $db->query($procedure);
if ($result) {
// Cycle through results
while ($row = $result->fetch_object()) {
//添加到對象數(shù)組
$arr[] = $row;
}
// 這里是最重要的,需要將游標(biāo)移動(dòng)下一個(gè)結(jié)果集
$result->close();
$db->next_result();
}

更多關(guān)于thinkPHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結(jié)》、《ThinkPHP常用方法總結(jié)》、《smarty模板入門基礎(chǔ)教程》及《PHP模板技術(shù)總結(jié)》。

希望本文所述對大家基于ThinkPHP框架的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論