joshyfrancis / mysql_backup_restore_php Goto Github PK
View Code? Open in Web Editor NEWMysql database backup/restore system in PHP
License: MIT License
Mysql database backup/restore system in PHP
License: MIT License
NEED A SCRIPT THAT MAKE AUTO EXPORT IN .CSV FILE JUST ONE TABLE OF MY DATABASE
BUT I CANT MAKE
LOOK THIS EXAMPLE
`<?php
/*
////////////////////////////////////////////////////////////////////////////
function aedbttf_add_custom_cron_schedule($schedules) {
//Every 15 minutes
$schedules['every15minutes'] = array(
'interval' => 900,
'display' => __('Every 15 minutes')
);
//Every 30 minutes
$schedules['every30minutes'] = array(
'interval' => 1800,
'display' => __('Every 30 minutes')
);
return $schedules;
}
add_filter('cron_schedules', 'aedbttf_add_custom_cron_schedule');
////////////////////////////////////////////////////////////////////////////
function aedbttf_activation_hook() {
wp_clear_scheduled_hook( 'aedbttf_db_table_auto_export_cron_hook' );
if ( ! wp_next_scheduled( 'aedbttf_db_table_auto_export_cron_hook' ) ) {
wp_schedule_event( time(), 'hourly', 'aedbttf_db_table_auto_export_cron_hook' ); //Use 'hourly' or custom interval defined in aedbttf_add_custom_cron_schedule above. Plugin needs to be de-activated and re-activated for schedule to be changed
}
}
register_activation_hook( FILE , 'aedbttf_activation_hook' );
add_action( 'aedbttf_db_table_auto_export_cron_hook', 'aedbttf_do_db_table_export' );
////////////////////////////////////////////////////////////////////////////
function aedbttf_deactivation_hook() {
wp_clear_scheduled_hook( 'aedbttf_db_table_auto_export_cron_hook' );
}
register_deactivation_hook( FILE , 'aedbttf_deactivation_hook' );
////////////////////////////////////////////////////////////////////////////
function aedbttf_do_db_table_export() {
///////////////////////////////////////////////////////////////////////////
//MAKE CHANGES HERE
$filename = "my-db-table.csv"; //Just the filename you want to use WITHOUT the path. Include .csv extension
$columns = "column2,column3,column4"; //Comma seperated list of columns to retrieve from DB in MySQL query
$table_name = "mytablename"; //Just the DB table name by itself WITHOUT the prefix
$where = "WHERE somecolumn='sometext'"; //MySQL WHERE options or set to "" for none. Example: WHERE somecolumn='sometext'
$order_by = "ORDER BY anothercolumn DESC"; //MySQL ORDER BY options or set to "" for none. Example: ORDER BY anothercolumn DESC
$limit = "LIMIT 250"; //MySQL LIMIT options or set to "" for none. Example: LIMIT 250
$header_row = $columns; //Comma seperated list to use as header row in CSV file. Set to "" for no header row. Default is set to = $columns;
//DO NOT CHANGE ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING
///////////////////////////////////////////////////////////////////////////
global $wpdb;
$table_name = $wpdb->prefix.$table_name; //Add prefix to table name
$query = "SELECT {$columns} FROM `{$table_name}` {$where} {$order_by} {$limit}"; //Create MySQL query string
$results = $wpdb->get_results($query, ARRAY_A); //Do MySQL databse query
if ($header_row != "") {
$output = $header_row; //Set header row for CSV file
} else {
$output = ""; //No header row in CSV file
}
foreach ($results as $row) {
$output = $output."\r\n";
$columns_array = split(",",$columns);
$first_column = true;
foreach ($columns_array as $column) {
if ($first_column != true) {
$output = $output.",";
} else {
$first_column = false;
}
$output = $output.$row[$column];
}
}
//WARNING: Files written to plugin_dir_path are PUBLICLY accessible in the /wp-content/plugins/auto-export-db-table-to-file/ directory.
$filename = plugin_dir_path( __FILE__ ).$filename; //Add path to plugin directory
$file_handle = fopen($filename, 'w'); //Open file for write
fwrite($file_handle, $output); //Write output to file
fclose($file_handle); //Close file
}
?>`
actually it is not working on my site and tried in local too and tried in two of my other sites.
Don't know what is the issue is>>>>
Hello,
I am using your script but it is not showing databases list, neither in mamp nor on live server. What can be the issue. Please reply.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.