'Separate SQL commands in PHP

I have a (dynamically generated) file that includes a lot of SQL Statements that contain only data definition.

Usually, I run the whole script as a single transaction via pg_query. Is there an efficient and safe way to separate the SQL commands in PHP in order to split them in several transactions?

Like splitting the whole string by ; but avoiding errors due to usage of ; within quotes?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source