xc0n Posted August 6, 2011 Share Posted August 6, 2011 hey i want a php file to backup my mysql database into a .sql file for me im using the code below, I save this code as backup.php and when i visit backup it says "Database Backup Completed" but the database backup folder is empty it doesnt create or write to the sql file.. ive also tryed giving the file and folder permissions 755, 775 & 777 and still none worked! not sure whats wrong? <?php // Connect To Database $dbhost = 'localhost'; $dbuser = 'database_user'; $dbpass = '***********'; $dbname = 'database_name'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error Connecting to MYSQL'); mysql_select_db($dbname); // End $backupFile = 'backup_folder/backup_file.sql'; mysql_query("SELECT * FROM '$dbname' -> INTO OUTFILE '$backupFile'"); $result = mysql_query; if($result) { echo "Database Backup Completed"; } else { echo "There Was A Error"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/244047-use-a-php-file-to-backup-a-mysql-database/ Share on other sites More sharing options...
AyKay47 Posted August 6, 2011 Share Posted August 6, 2011 cleaned up your code, try this.. <?php ini_set("error_reporting", E_ALL); ini_set("display_errors","ON"); // Connect To Database $dbhost = 'localhost'; $dbuser = 'database_user'; $dbpass = '***********'; $dbname = 'database_name'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error Connecting to MYSQL: '.mysql_error()); mysql_select_db($dbname); // End $backupFile = 'backup_folder/backup_file.sql'; $result = mysql_query("SELECT * FROM '$dbname' -> INTO OUTFILE '$backupFile'"); if($result) { echo "Database Backup Completed"; } else { echo "There Was A Error";} ?> do you receive any errors after you update you code? Quote Link to comment https://forums.phpfreaks.com/topic/244047-use-a-php-file-to-backup-a-mysql-database/#findComment-1253328 Share on other sites More sharing options...
jcbones Posted August 6, 2011 Share Posted August 6, 2011 http://www.dwalker.co.uk/phpmysqlautobackup/ Quote Link to comment https://forums.phpfreaks.com/topic/244047-use-a-php-file-to-backup-a-mysql-database/#findComment-1253369 Share on other sites More sharing options...
xc0n Posted August 7, 2011 Author Share Posted August 7, 2011 @AyKay47: hey thanks alot for the help but that code gave me white page saying: There Was A Error @jcbones: that script works great and does everything i need it to do! thanks alot, it can even email me the backup zipped or send it to a remote ftp server! very nice!! Quote Link to comment https://forums.phpfreaks.com/topic/244047-use-a-php-file-to-backup-a-mysql-database/#findComment-1253574 Share on other sites More sharing options...
AyKay47 Posted August 7, 2011 Share Posted August 7, 2011 The code I provided was not meant to be a fix, simply to debug. Glad you found a solution Quote Link to comment https://forums.phpfreaks.com/topic/244047-use-a-php-file-to-backup-a-mysql-database/#findComment-1253575 Share on other sites More sharing options...
xc0n Posted August 7, 2011 Author Share Posted August 7, 2011 Yea i understand, but thanks alot for taking to time to help me! Quote Link to comment https://forums.phpfreaks.com/topic/244047-use-a-php-file-to-backup-a-mysql-database/#findComment-1253578 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.