Jump to content

Recommended Posts

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";
}
?>

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?

@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!!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.