如何在for循环中调用存储过程

时间:2022-09-21 00:13:21

i have php code as folloes where i call store procedure inside for loop.But when i execute m getting eror "Commands out of sync; you can't run this command now " but if i remove for loop m getting correct result

我有php代码作为folloes我在里面调用存储过程for循环。但是当我执行m得到eror“命令不同步;你现在不能运行此命令”但如果我删除for循环m得到正确的结果

<?php 
$sum=0;
for($i=0;$i<10;$i++){
    $overall_sat=mysql_query("call daily_sales('HO Bangalore','2013-07-01','2013-07-30')");

        while($row=mysql_fetch_row($overall_sat)){ echo "<pre>"; print_r($row);?>
            <td><?php echo $row['0'];
            $sum=$sum+$row['sat'];?></td>
        <?}
}
if(!$overall_sat){
    echo mysql_error();
}
?>

1 个解决方案

#1


0  

your connection is going lost so before calling stored procedure first close the connection and again create connectivity with database

您的连接将丢失,因此在调用存储过程之前首先关闭连接并再次创建与数据库的连接

<?php 
$sum=0;
for($i=0;$i<10;$i++){
    mysql_close();          // close connection
   // create connectivity

    $overall_sat=mysql_query("call daily_sales('HO Bangalore','2013-07-01','2013-07-30')");

        while($row=mysql_fetch_row($overall_sat)){ echo "<pre>"; print_r($row);?>
            <td><?php echo $row['0'];
            $sum=$sum+$row['sat'];?></td>
        <?}
}
if(!$overall_sat){
    echo mysql_error();
}
?>

#1


0  

your connection is going lost so before calling stored procedure first close the connection and again create connectivity with database

您的连接将丢失,因此在调用存储过程之前首先关闭连接并再次创建与数据库的连接

<?php 
$sum=0;
for($i=0;$i<10;$i++){
    mysql_close();          // close connection
   // create connectivity

    $overall_sat=mysql_query("call daily_sales('HO Bangalore','2013-07-01','2013-07-30')");

        while($row=mysql_fetch_row($overall_sat)){ echo "<pre>"; print_r($row);?>
            <td><?php echo $row['0'];
            $sum=$sum+$row['sat'];?></td>
        <?}
}
if(!$overall_sat){
    echo mysql_error();
}
?>