Export/Backup MySQL Database like phpMyAdmin

If you want to backup you mysql database by php script like phpMyadmin do you can use below function, something like for auto backup system or manual backup from admin panel of your webapp. Call the function with database name and a path to save backup( leave blank for current dir)