1) COMPLETELY PROCESS THE XML FIRST
I will process the complete XML file and put the data into separate arrays based upon the tables that the data needs to go into.
here is an example of what I mean:
$movies[movieid][name] $movies[movieid][plot] $movies[movieid][runningtime] etc. $actors[actorid][fname] $actors[actorid][lname] $actor_movie[actorid] = movieid1 $actor_movie[actorid] = movieid2 etc.
The benefit with this method is that I will not have to process a lot of duplicates with things such as actors, studios, etc. I will have a single entry in the $actors array for each actor and I would only have to check once to see if it already exists in the database. The downside would be that I may get some very large arrays as the XML file will contain hundreds, possibly thousands, of movie records.
1) INPUT RECORDS INTO DATABASE AS THEY ARE PROCESSED
In this scenario I would insert records for each applicable record as they are processed. So, I process the first movie I would insert the records for that movie. Then as I process the actors for that movie I would insert the actors for that movie
But I would first have to do a query to see if the actor already exists. So, as I go through each movie if the same actor exists in 20 movies I would be doing a check 20 times to see if that actor already exists. All of these duplicative queries could be less efficient than the method above.
I hope this all makes sense. Anyone have a suggestion?