$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`";
Voeg ;
toe om twee SQL-instructies te combineren.
U kunt deze zoekopdrachten op deze manier combineren.
$insertSQL_Single = $insertSQL1.";".$insertSQL2.";".$insertSQL3;
resulterende zoekopdracht :
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`
Ik heb dit geprobeerd met PhpMyAdmin. zoekopdracht is gelukt
het kan niet worden uitgevoerd door mysql_query() . laten we wat andere trucs vinden. we moeten het apart uitvoeren.
Gebruik mysqli om dit uit te voeren
$mysqli = new mysqli("host","username","password", "databasename");
if (!$mysqli->multi_query($insertSQL_Single)) {
echo "Multi query failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
else
{
echo "success";
}