I was asked to create an export and import mysql database with it's structure and data into a .sql file using php scripting and not phpmyadmin to make the user be able to backup his data?
Does anybody have an idea how to do that??
Thanks in advance
解决方案
either
$tableName = 'mypet';
$backupFile = 'backup/mypet.sql';
$query = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName";
$result = mysql_query($query);
or
$backupFile = $dbname . date("Y-m-d-H-i-s") . '.gz';
$command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname | gzip > $backupFile";
system($command);