> Is there an easy way to do a mysql dump routine written in php? I > basically want to write a function to backup a database and have it > create all the neccessary structures and data in the dump. I know > phpMyAdmin will do this for me, but I want to write a function to do > this incase the server doesn't have phpMyAdmin installed. Any ideas?
Why not use the existing mysqldump command-line utility? function mysql_dump($db, $user, $pass) { return shell_exec("/path/to/mysqldump --user={$user} --password={$pass} --complete-insert --add-drop-table {$db}"); } Or, skip PHP entirely and place a call to mysqldump with a suitable select-privilege-only username & password in a cron job, if you're on a unix machine. I use the following shellscript to do periodic backups to RCS repositories in /usr/local/var/backups: #!/bin/sh if [ $# -ne 3 ]; then echo 'Usage:'; echo ' mysql-backup.sh <db-user> <db-password> <db-name>'; exit; fi; USER=$1; PASS=$2; DB=$3; MYSQLDUMP=/usr/local/bin/mysqldump; BACKUP_DIR=/usr/local/var/backups; SQL_FILE=$DB.mysql; RCS_FILE=$SQL_FILE,v; cd $BACKUP_DIR; $MYSQLDUMP --user=$USER --password=$PASS --complete-insert --add-drop-table $DB > $SQL_FILE; #### the remaining lines can be ommitted if RCS isn't needed #### if [ ! -f $RCS_FILE ]; then echo "import" | rcs -q -i $SQL_FILE; else rcs -q -l $RCS_FILE; fi; echo "mysql_backup.sh" | ci -q $SQL_FILE; --------------------------------------------------------------------- michal migurski- contact info and pgp key: sf/ca http://mike.teczno.com/contact.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php