I have a php-script that is to get data and insert that data into an MSSQL (v12) table. The table should be emptied before inserting.
I have:
$connPdo->query("TRUNCATE TABLE [Table]");
$get_data = callAPI('GET', 'https://api...);
$response = json_decode($get_data, true);
foreach ( $response['FOO'] as $Lines )
$Proginsert = $connPdo->query("INSERT INTO [Table] (FEE, FIE)
VALUES('".$Lines[A]."','" .$Lines[B]."')");
Problem is that sometimes it works OK, sometimes the TRUNCATE is not finished before the first INSERT arrives to the database which leads to some old data beeing kept in the table.
I need a way to hold off the INSERTS until the TRUNCATE is done.