I would generally recommend using mysqlhotcopy, mainly because its faster than mysqldump, although it uses locks.
But since you need a PHP script to do the work you probably don't have access to the server?!
Check it out
http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html