Categories
PHP

PHP class to export MySQL tables and optimize them

Hello,

Today I am going to share a helpful library that I use some times to perform backups of the schema from a DB.

It will create a unique file with the schema for each table you have in your DB for example. Also I added an option to get all the data and you can optimize a set of tables.

How to use it:

$mu = new my_utils('root','','localhost','oc');

/**
 * Export schemas into multiple files
 */
$mu->export();//only schema default, all the tables
$mu->export(__DIR__.'/export/',array('oc_accounts','oc_categories'),TRUE,TRUE);

/**
* Optimize tables
*/
$mu->optimize_tables(array('oc_posts','oc_locations'));
$mu->optimize_tables();//all the tables

/**
* changes DB
*/
$mu->set_dbname('ocaku');

/**
 * shows all the tables from a db
*/
var_dump($mu->show_tables());

/**
* returns the create for a single table
*/
echo $mu->show_create_table('pages');//1 table
echo $mu->show_create_table('pages',TRUE);//1 table with the data

Download the class my_utils.