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