Ok, I did some checking and I had definitely messed up the error reporting. It was echoing $query but the error was from a different statement that didn't reference $query at all ($queryScans). Now, when I set php error reporting to E_ALL, some errors made some more sense. There are some undefined indexes which are causing the 1064 error. Before I assumed that those were a result of the failed query since the lines reported were after - but that was because the error was reporting the wrong query all together.
To make a long story short, there seems to be an issue with my XML to Array function. I will mark this thread as resolved and create a new one for the new issue.
Thank you for all the help, I really appreciate it.