SBMD - Backup of specific tables
Posted: 27 May 2016, 17:27
Hi Admin,
I would like to know, how can I use this script:
https://coursesweb.net/php-mysql/simple- ... atabase_s2
to make backup of specific tables and how to restore these specific tables? Do you have any examples code for this?
For example, in the code you provide on the website:
I am trying to do the same but for specific tables in my Database and I cannot figure out it. PLease see the code below:
NOTE:At this point the class will return me a string and I cannot backup it in a Z.IP file or .SQL file because the next function for saving just use an array as input.
I would appreciate any advise.
By the way, it is an excellent work.
Kind regards
I would like to know, how can I use this script:
https://coursesweb.net/php-mysql/simple- ... atabase_s2
to make backup of specific tables and how to restore these specific tables? Do you have any examples code for this?
For example, in the code you provide on the website:
Code: Select all
//data for connecting to MySQL
$conn_data = ['host'=>'localhost', 'user'=>'user_name', 'pass'=>'password', 'dbname'=>'database_name'];
$lang ='en'; //indice of the "lang_...json" file with texts
$dir ='backup/'; //folder to store the ZIP archive with SQL backup
//set object of backupmysql class
include 'backupmysql.class.php';
$bk = new backupmysql($lang, $dir);
$bk->setMysql($conn_data); //set connection
$tables = $bk->getTables(); //get array with all the tables in database
//if no error
if($bk->error === false){
//if tables, creates the SQL backup of all the tables and saves it in ZIP archive (get succesful or error message)
$bk_sql = (count($tables) >0) ? $bk->saveBkZip($tables) :'No tables in database';
echo $bk_sql;
}
else echo $bk->error;
Code: Select all
//data for connecting to MySQL
$conn_data = ['host'=>'localhost', 'user'=>'root', 'pass'=>'', 'dbname'=>'test'];
$lang ='en'; //indice of the "lang_...json" file with texts
$dir ='wp-content/themes/TEST/backups'; //folder to store the ZIP archive with SQL backup
$bk = new backupmysql($lang, $dir);
$bk->setMysql($conn_data); //set connection
$important_tables = array('patients','patientrecords');
$tables = $bk->getSqlBackup($important_tables); //get array with all the tables in database
Code: Select all
//if no error
if($bk->error === false){
//if tables, creates the SQL backup of all the tables and saves it in ZIP archive (get succesful or error message)
$bk_sql = (count($tables) >0) ? $bk->saveBkZip($tables) :'No tables in database';
echo $bk_sql;
}
else echo $bk->error;
By the way, it is an excellent work.
Kind regards