$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`";
Добавете ;
за комбиниране на два SQL оператора.
Можете да комбинирате тези заявки по този начин.
$insertSQL_Single = $insertSQL1.";".$insertSQL2.";".$insertSQL3;
получена заявка:
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`
Опитах това с помощта на PhpMyAdmin. заявката беше успешна
не може да се изпълни от mysql_query() . нека намерим други трикове. трябва да го изпълним отделно.
Използвайте 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";
}