I am inserting bulk values using prepared statements, assigning values and execution is done in loop still it is taking too long and exceeding the execution limit.
Here is my code:
if(isset($_GET['mov_id']) && isset($_GET['season']))
{
$id= $_GET['mov_id'];
$season = $_GET['season'];
$stmt = $DB_con->prepare("SELECT * FROM `mov_movies` where moviesID =:id");
$stmt->execute(array(':id'=>$id));
$row=$stmt->fetch(PDO::FETCH_ASSOC);
$imdbID = $row['IMDBid'];
if(isset($_POST['btn-addmovie']))
{
$episodes = trim($_POST['tepisodes']);
$name = "";
$episode = "";
$DOR = "";
$IMDB = "";
$drive = "";
$cdn = "";
$stmt = $DB_con->prepare("DELETE FROM `mov_season` where movId =:id");
$stmt->execute(array(':id'=>$id));
$count = 1;
$stmt = $DB_con->prepare("INSERT INTO `mov_season` (`movId`, `season`, `episode`, `releaseDate`, `IMDB`, `driveLink`, `cdnLink` , `title`) VALUES (:id, :season, :episode,:releaseDate, :IMDB,:drive,:cdn,:name)");
$stmt->bindparam(":id", $id);
$stmt->bindparam(":season", $season);
$stmt->bindparam(":episode", $episode);
$stmt->bindparam(":releaseDate", $DOR);
$stmt->bindparam(":IMDB", $IMDB );
$stmt->bindparam(":drive", $drive );
$stmt->bindparam(":cdn", $cdn );
$stmt->bindparam(":name", $name);
while($count < $episodes){
$name = trim($_POST['name'.$count]);
$episode = trim($_POST['episode'.$count]);
$DOR = trim($_POST['DOR'.$count]);
$IMDB = trim($_POST['imdb'.$count]);
$drive = trim($_POST['drive'.$count]);
$cdn = trim($_POST['cdn'.$count]);
if(($drive != "") || ($cdn = "")){
$stmt->execute();
$count++;
}
}
$success = "Successfully Updated!";
}
}
Statement is taking place in if loop inside while loop. And even for only one execution it exceeds 120 sec of execution time.