$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`";
Lägg till ;
för att kombinera två SQL-satser.
Du kan kombinera dessa frågor så här.
$insertSQL_Single = $insertSQL1.";".$insertSQL2.";".$insertSQL3;
resulterande fråga:
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`
Jag har provat detta med PhpMyAdmin. frågan lyckades
det kan inte köras av mysql_query() . låt oss hitta några andra knep. vi måste utföra det separat.
Använd mysqli för att utföra detta
$mysqli = new mysqli("host","username","password", "databasename");
if (!$mysqli->multi_query($insertSQL_Single)) {
echo "Multi query failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
else
{
echo "success";
}