In the end, after much looking into the issue and leaving it, letting it ripen in my mind, I was able to find exactly what I needed by using mysqldump:
exec('mysqldump --user=XXX --password=XXX --host=localhost DBNAME > outputfile.sql');
Hope it might help someone else out there!
P.S. Thanks a lot to @hellosheikh for the answer. It did provide very interesting info that might prove handy later on. However, for my exact needs, this second way in the end proved more practical.