Okay, I gone through many problems this past few months and one thing i learned is always keep a backup of all your data from the server. The most important thing which should not be manipulated by anything is your database.
Most of them would be knowing this but for those who are unaware please read along to stay safe.
There are many ways to get backup of your database , I will show you 3 simplest possible ways.
Execute a database backup query from PHP file.
By using SELECT INTO OUTFILE query for creating table backup
Code:
<?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';
?>
For Restoring the backup you just need to run LOAD DATA INFILE query
Code:
<?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';
?>
Run mysqldump using system() function
The system() function is used to execute an external program. Because MySQL already have built in tool for creating MySQL database backup (mysqldump) use it from own PHP script like :
Code:
<?php
include 'config.php';
include 'opendb.php';
$backupFile = $dbname . date("Y-m-d-H-i-s") . '.gz';
$command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname | gzip > $backupFile";
system($command);
include 'closedb.php';
?>
Use phpMyAdmin to do the backup
The most easiest and convenient way to get your database backup.
To backup your MySQL database using phpMyAdmin click on the "export" link on phpMyAdmin main page. Choose the database you wish to backup, check the appropriate SQL options and enter the name for the backup file.
If you still get any problems with your server or Database contact any of the Staff members of FG , we would definitely help you out.
The Admins are really helpful , I remember when i was stuck in some problem the Admins helped me out with the utmost ease .