$insertSQL1 = "INSERT INTO sr1_full (`date`, `total_pending`, `appt_today`, `percent_appt_today`) SELECT `date`, `total_pending`, `appt_today`, `percent_appt_today` FROM `sr1`";
$insertSQL2 = "INSERT INTO sr2_full (`date`, `total_pending`, `appt_today`, `percent_appt_today`) SELECT `date`, `total_pending`, `appt_today`, `percent_appt_today` FROM `sr2`";
$insertSQL3 = "INSERT INTO sr3_full (`date`, `total_pending`, `appt_today`, `percent_appt_today`) SELECT `date`, `total_pending`, `appt_today`, `percent_appt_today` FROM `sr3`";
Přidejte ;
zkombinovat dva příkazy SQL.
Tyto dotazy můžete takto kombinovat.
$insertSQL_Single = $insertSQL1.";".$insertSQL2.";".$insertSQL3;
výsledný dotaz:
INSERT INTO sr1_full (`date`, `total_pending`, `appt_today`, `percent_appt_today`) SELECT `date`, `total_pending`, `appt_today`, `percent_appt_today` FROM `sr1`;INSERT INTO sr2_full (`date`, `total_pending`, `appt_today`, `percent_appt_today`) SELECT `date`, `total_pending`, `appt_today`, `percent_appt_today` FROM `sr2`;INSERT INTO sr3_full (`date`, `total_pending`, `appt_today`, `percent_appt_today`) SELECT `date`, `total_pending`, `appt_today`, `percent_appt_today` FROM `sr3`
Zkoušel jsem to pomocí PhpMyAdmin. dotaz byl úspěšný
nelze jej spustit pomocí mysql_query() . pojďme najít nějaké další triky. musíme to provést samostatně.
Pro spuštění použijte mysqli
$mysqli = new mysqli("host","username","password", "databasename");
if (!$mysqli->multi_query($insertSQL_Single)) {
echo "Multi query failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
else
{
echo "success";
}