Try putting the prepare back in with $heredoc as its parameter.
In reply to Re^3: Unable to run SQL query by Mr. Muskrat in thread Unable to run SQL query by Rocko19