-3
$update_all_data = "UPDATE new_cases,new_recoveries,new_deaths SET new_cases.cases='$total_covid_cases',new_recoveries.recoveries='$total_covid_recoveries',new_deaths.deaths='$total_covid_deaths' WHERE new_cases.id= 1 AND new_recoveries.id=1 AND new_deaths.id=1";
    $result_all_update = mysqli_multi_query($conn,$update_all_data);

I want to update 3 tables at the same time. I am out of ideas how to it, Can somebody please help me...

  • You can concatenate your queries and made a multistament query, you need to enable it in the sdk, in the another hand, you can prepare a transaction and executes procedural, this last is the best practice. https://www.php.net/manual/en/mysqli.quickstart.multiple-statement.php – BlackSlash May 21 '22 at 14:32
  • 1
    This is obviously a coding exercise, please look into prepared statements before you get bad habits. Building SQL statements from concatenated strings is rather dangerous. Here's a ref for PHP prepared statements: https://www.php.net/manual/en/mysqli.prepare.php – Samuel Åslund May 21 '22 at 14:34
  • @BlackSlash did you mean my dbConnection? – Sposhal Gamer May 21 '22 at 14:35
  • If you really mean "Simultaneously" you also need to look into transactions. Ref: https://www.php.net/manual/en/mysqli.begin-transaction.php – Samuel Åslund May 21 '22 at 14:36
  • check the comment of @SamuelÅslund is the best practice! – BlackSlash May 21 '22 at 14:39
  • For an illustration about what I mean by "rather dangerous" have a look at this XKCD strip: https://xkcd.com/327/ Oh, and I think you need to reformulate your question, because I see nothing obviously wrong with the above code unless you try to re-run it to get more than one row in the new_* tables, then your fixed id will bite you. – Samuel Åslund May 21 '22 at 14:44

0 Answers0