I don't know why you are doing that in your app. You can easily retrieve your full database at the database level using a MySQL command or phpMyAdmin.
Example:
mysqldump -u root -p my_database > my_database_backup.sql