加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

php执行多个存储过程的方法【基于thinkPHP】

发布时间:2020-12-14 14:06:25 所属栏目:大数据 来源:网络整理
导读:本篇章节讲解php执行多个存储过程的方法。供大家参考研究具体如下: 从以前的使用原生代码来看,只需要将结果集关闭即可,即 queryID -> close(); 使用mysqli方式,修改DbMysqli.class.php,将query函数改为: initConnect(false); if (!$this ->

本篇章节讲解php执行多个存储过程的方法。分享给大家供大家参考,具体如下:

从以前的使用原生代码来看,只需要将结果集关闭即可,即

queryID -> close();

使用mysqli方式,修改DbMysqli.class.php,将query函数改为:

initConnect(false); if (!$this -> _linkID) { return false; } $this -> queryStr = $str; //释放前次的查询结果 if ($this -> queryID) $this -> free(); N('db_query',1); // 记录开始执行时间 G('queryStartTime'); $this -> queryID = $this -> _linkID -> query($str); // 对存储过程改进 $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(); } //主要将这段移动了一下,关闭结果集 if ($this -> _linkID -> more_results()) { while (($res = $this -> _linkID -> next_result()) != NULL) { $this -> queryID -> close(); } } return $ret ; }

下面就可以调用多个存储过程,或许执行其他SQL操作,可以直接使用M函数

在使用thinkphp的时候发现执行多个存储过程只能执行第一个,看了一下源码Driver/Db/DbMysql.class,已经对存储过程进行了一定处理,但是不知道为什么运行不了。

用原生代码解决了问题(下面是部分代码):

"; $arr = array(); // 1st Query $procedure = "call p1()"; $result = $db->query($procedure); if ($result) { // Cycle through results while ($row = $result->fetch_object()) { //添加到对象数组 $arr[] = $row; } // 这里是最重要的,需要将游标移动下一个结果集 $result->close(); $db->next_result(); } $procedure = "call p2()"; $result = $db->query($procedure); if ($result) { // Cycle through results while ($row = $result->fetch_object()) { //添加到对象数组 $arr[] = $row; } // 这里是最重要的,需要将游标移动下一个结果集 $result->close(); $db->next_result(); }

更多关于thinkPHP相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》及《》。

希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读