dream890110 2015-05-24 23:23
浏览 57

如何在php中连续调用3个存储过程mysql

I want to call 3 stored procedures consecutively using result from previous to call next procedure.

For now, I arrived to call 2 but the third fail. How can I do please?

This is my code:

//First stored procedure CALL
$spots = $mysqli->query("CALL getAllSpots()", MYSQLI_STORE_RESULT);
while($spot = $spots->fetch_array(MYSQLI_ASSOC)) {

    $ville = $row["city"];
    $weather =file_get_contents("http://api.openweathermap.org/data/2.5/forecast?q=$ville&mode=json");
    $json = json_decode($weather, true);

    $liste = $json["list"];

    $id = (int) $spot['id'];

    // Free stored results
    clearStoredResults($mysqli);

    // Execute second SP using value from first as a parameter (MYSQLI_USE_RESULT and free result right away)
    $previsions = $mysqli->query("CALL getPrevisionOnSpot($id)", MYSQLI_USE_RESULT);
    $dataRow = $previsions->fetch_array(MYSQLI_ASSOC);

    $row_cnt = $previsions->num_rows;

    // Free results from second SP
    $previsions->free();
    for ($i = 0; $i<8; $i++){ // Récupère que les données du jour
        $data = $liste[$i];

        // Calcul with $data .........

        //Third call that fail
        if ($row_cnt == 0){
            $result = $mysqli->query("CALL addPrevisionOnSpot($meteo,$temperature,$vitesse,$directionReel,$datetime,$id)",MYSQLI_USE_RESULT);
        }
        else {
            $result = $mysqli->query("CALL updatePrevisionOnSpot($meteo,$temperature,$vitesse,$directionReel,$datetime,$id)");
        }
    }

    // And the function to clear stored result
    function clearStoredResults($mysqli_link){
    while($mysqli_link->next_result()){
        if($l_result = $mysqli_link->store_result()){
            $l_result->free();
        }
    }
}

When I launch my code, I have bool(false) for third procedure

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 目详情-五一模拟赛详情页
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line