使用存储过程时PHP错误 [英] php error when using stored procedure
问题描述
我有一个包含4个菜单(产品,供应商,购买,客户)的php代码.每个菜单都有其自己的存储过程.每个意思是这些代码:
I have a php code with 4 Menus(products,suppliers,purchases,customers). Each menu has its own stored procedure. EACH meanu has these code:
产品代码:
<?php
$sql=$mysqli->query("call selectproducts()");
$i=1;
while($row=mysqli_fetch_array($sql)){
$id=$row['prodid'];
$date=$row['prodname'];
$item=$row['proddescription'];
$qtyleft=$row['prodsupplier'];
$qty_sold=$row['proddate'];
$price=$row['prodprice'];
$sales=$row['prodquantity'];
if($i%2){
?>
<tr id="<?php echo $id; ?>" class="edit_tr">
<?php } else { ?>
<tr id="<?php echo $id; ?>" bgcolor="#f2f2f2" class="edit_tr">
<?php } ?>
<td class="edit_td"><span class="text"><?php echo $date; ?></span> </td>
<td><span class="text"><?php echo $item; ?></span> </td>
<td><span class="text"><?php echo $qtyleft; ?></span></td>
<td><span id="last_<?php echo $id; ?>" class="text">
<?php
echo $qty_sold;
?>
我的问题是,每当我尝试在其他菜单或什至在1个菜单中使用存储过程时,此错误在其他平均值(供应商,采购,客户)中出现:
My problem is whenever I tried to use stored procedure in other menus or even in 1 menu this error in other meanus (suppliers,purchases,customers):
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given
简而言之,如果我只包含一个(1)存储过程,就会发生错误.一切正常的唯一事情就是当我以正常方式使用它时(从表中选择*).
To make it short, If i included just even one(1) stored procedured, the error occurs. The only thing that everything will work is that when i use it in normal way (SELECT * from table).
可能是什么问题?请帮助我.这是我项目中唯一的问题.
What could be the problem?please help me..This is the only problem in my project.
Mysql存储过程代码:
Mysql Stored Procedure Code:
CREATE DEFINER=`root`@`localhost` PROCEDURE `selectproducts`()
begin
select * from products order by ProdID;
end
这是完整的代码: http://jsfiddle.net/WKKD4/
Here's the full code: http://jsfiddle.net/WKKD4/
对不起,我没有其他地方可以戴上它.
Sorry I have no other place to put it on.
推荐答案
尝试以下方法:
**
$sql->close();
$mysqli->next_result();
**
在获取结果之后放置它并查看魔术.
Place this after fetching the results and see the magic.
这篇关于使用存储过程时PHP错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!