View Single Post
Old 01-14-2008, 09:27 PM   #1 (permalink)
Gareth
The Acquainted
 
Gareth's Avatar
 
Join Date: Jan 2008
Posts: 136
Thanks: 4
Gareth is on a distinguished road
Default Backing up a Database NOT via PHPMyAdmin

Hello.

I would like to be able to back up parts of my database by providing a form / link which will give the admin the choice to download the file in a sql format (like in IPB).

I have researched this a little; and been succesful in being able to backup the database into a location on the server where I define, but I'm not sure how I can change it into being download-able (obviously if it is downloaded I don't want it on the server anymore...).

This is what I have so far (I have commented it):

PHP Code:
<?php
include 'conf_global.php'// File with database settings

$tableName  'a_table'// The table which the admin has chosen to backup (Static for exemplory reasons)
$backupFile 'backup/DATE_TABLE.sql'// Where the sql is places
$query      "SELECT * INTO OUTFILE '$backupFile' FROM $tableName"// Back up table into file
$result mysql_query($query); // Query it

if ($result){
    echo 
'Database Backed Up';    // If succesful
}
else {
    echo 
'Database NOT Backed Up'// If not..
}
?>
Can someone help me please?
Much appreciated.
Gareth
Gareth is offline  
Reply With Quote