Home  >  Article  >  Backend Development  >  php怎么去获得mysql有返回值有查询的存储过程

php怎么去获得mysql有返回值有查询的存储过程

WBOY
WBOYOriginal
2016-06-13 10:42:41747browse

php如何去获得mysql有返回值有查询的存储过程
存储过程
create procedure a(out b int)
begin
  select 10;
  set b=3;
end;

PHP
$tsql .= "call a(@b);";
$tsql .= "select @b;";
if($mysqli->multi_query($tsql)) {
  if($result = $mysqli->store_result()) {
  while($row = $result->fetch_array()) {
  array_push($data['table'], $row);
  }
  }
  if($mysqli->more_results()){ // 判断还有没有结果集
  if($mysqli->next_result()) {
  if($result = $mysqli->store_result()) {
  if($row = $result->fetch_row()) {
  for($i = 0, $count = count($row); $i   $data['output'][$i] = $row[$i];
  }
  }
  }
  }
  }
} else {
  echo "ERROR:", $mysqli->errno, "---", $mysqli->error;
}
print_r($data['output']);

没办法获取返回值 如果是不带返回值 直接select b的话 就可以 又或者存储过程里不要查询也可以
同时两个都有的话就无法得到返回值
这该如何解决

------解决方案--------------------

PHP code
<?php 2     define('CLIENT_MULTI_RESULTS', 131072); 3  4     $link = mysql_connect("127.0.0.1", "root", "",1,CLIENT_MULTI_RESULTS) or die("Could not connect: ".mysql_error()); 5     mysql_select_db("vs") or die("Could not select database"); 6 ?> 7  8 <?php 9         $result = mysql_query("call get_news_from_class_id(2)") or die("Query failed:" .mysql_error());10         while($row = mysql_fetch_array($result, MYSQL_ASSOC))11         {12                 $line = '<tr><td><a target="_blank" href="%5C''.%24row%5B%22url%22%5D.'%5C'">'.$row["title"].'('.$row["page_time"].')'.'</a></td>';14                 echo $line;15                 printf("\n");16 17         }18         mysql_free_result($result);19 ?>20 21 <?php22 mysql_close($link);23 ?><div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn