Without using database tool like phpMyAdmin, we can still back up data from MySql with PHP script that we made. Following some example of script to back up the data.
backup.php
<?php
mysql_connect('hostname','db_user','db_pass');
mysql_select_db('database_name');
$TableName='lecturer'; $BackupFile='E:\lecturer.sql';
$query="SELECT * INTO OUTFILE '$BackupFile' FROM $TableName"; $result=mysql_query($query);
if($result) echo "Success"; else echo "Failed";
?>
The name of output file also can add by folder name, for example :
$BackupFile=’E:\data\lecturer.sql’;
The extention of backup file not must be .sql but also can using .txt, .dat
To restore data from backup process, use this script
restore.php
<?php
mysql_connect('hostname','db_user','db_pass');
mysql_select_db('database_name');
$TableName='lecturer';
$BackupFile='lecturer.sql';
$query="LOAD DATA INFILE 'BackupFile' INTO TABLE $TableName";
$result=mysql_query($query);
if($result) echo "Restore Success";
else echo "Restore Failed";
?>
People Also Read
Filed under:
IT, Tips And Trick













I like tips n trick,..
littlebros last blog post..YM Online Status