1.取记录调用:
| call pr_pager('表名', '*', 25, 1, '', '', @count_rows); call pr_pager('user', '*', 15, 2, '', 'where id>3', @count_rows); call pr_pager('user', '*', 15, 1, 'group by password order by id desc', '', @count_rows); |
2.调用1后再取条数调用:
| select @count_rows; select @MAIN_STRING //select sql select @COUNT_STRING //seelct count sql |
支持多表级联 ,分组 :
| <?php function dump_single_form41report($sys_report_id) { $this->dbConn->setFetchMode(DB_FETCHMODE_ASSOC); //SET @a=1;CALL dbpi_report.simpleproc(@a);SELECT @a; $sql = "CALL dbpi_temp.dumpSingleReportForm41($sys_report_id);"; $result = $this->dbConn->query($sql); if (mysql_error()) { die (mysql_error().'<b>:</b> dump_single_form41report(...)['.__LINE__.'];<br>'.$sql); } return $result; } function initQueuePool($sys_report_id, $username){ $this->dbConn->setFetchMode(DB_FETCHMODE_ASSOC); $this->checkPreviousThread($sys_report_id, $username); $temptablename = "_".$username."_".$sys_report_id; $sql = "SET @a=".$sys_report_id.";"; $this->dbConn->query($sql); $sql = "SET @b='".DB_REPORT.".".$temptablename."';"; $this->dbConn->query($sql); $sql = "SET @c='".DB_PREPRODUCT."';"; $this->dbConn->query($sql); $sql = "CALL ".DB_REPORT.".fm41_simpleproc(@a,@b,@c);"; $this->dbConn->query($sql); } |
普通的查询,只返回一个结果集,而存储过程却返回至少两个结果集,其中一个就是存储过程的执行状态。我们必须要清除了这个执行状态以后,才可能再次调用另外一个存储过程 。
| <?php $rs=mysql_query("call pr_pager('change_monitor','*',10,1,'','',@p_out_rows)"); while($rows=mysql_fetch_array($rs)){ echo $rows[Schedule]; } $query=mysql_query("select @p_out_rows"); $v=mysql_fetch_array($query); can't return a result set in the given context |
需要php调用存储过程,返回一个结果集,发现很困难,找了半天,终于在老外的论坛上找到解决方案,这里本地化一下。
关键就是两点:
1.
| define('CLIENT_MULTI_RESULTS', 131072); |
2.
| $link = mysql_connect("127.0.0.1", "root", "",1,CLIENT_MULTI_RESULTS) or die("Could not connect: ".mysql_error()); |










