Quote:
Execute a database backup query from PHP file
Below is an example of using SELECT INTO OUTFILE query for creating table backup :
<?php
include 'config.php';
include 'opendb.php';
$tableName = 'mypet';
$backupFile = 'backup/mypet.sql';
$query = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName";
$result = mysql_query($query);
include 'closedb.php';
?>
To restore the backup you just need to run LOAD DATA INFILE query like this :
<?php
include 'config.php';
include 'opendb.php';
$tableName = 'mypet';
$backupFile = 'mypet.sql';
$query = "LOAD DATA INFILE 'backupFile' INTO TABLE $tableName";
$result = mysql_query($query);
include 'closedb.php';
?>
It's a good idea to name the backup file as tablename.sql so you'll know from which table the backup file is
|
Am I reading the logic of that right? I read it that it saves the table in the sql file and then the second one reads it and writes that into another table, based on the variables set? If so.. that would work for me..
Last edited by PauloMillerz; 02-06-2009 at 02:32 PM..
|