Php code: back up and restore the SQL database

Source: Internet
Author: User
Php (as the mainstream development language) Code: back up and restore the SQL database require (using des/application_top.php (as the mainstream development language); & nbsp; if (& #36; HTTP_GET_VARS [action]) & #123; & nbsp; switch (php (as the mainstream development language) Code: back up and restore SQL databases

Require (replicdes/application_top.php (as the mainstream development language ));

If ($ HTTP_GET_VARS [action]) {
Switch ($ HTTP_GET_VARS [action]) {
Case forget:
Tep_db_query ("delete from". TABLE_CONFIGURATION. "where configuration_key = DB_LAST_RESTORE ");
$ MessageStack-> add_session (SUCCESS_LAST_RESTORE_CLEARED, success );
Tep_redirect (tep_href_link (FILENAME_BACKUP ));
Break;
Case backupnow:
Tep_set_time_limit (0 );
$ Schema = # citespa, Open Source E-Commerce Solutions ."".
# Http://www.XXXXXX.com </a> ."".
#."".
# Database Backup For. STORE_NAME ."".
# Copyright (c). date (Y)... STORE_OWNER ."".
#."".
# Database:. DB_DATABASE ."".
# Database Server:. DB_SERVER ."".
#."".
# Backup Date:. date (php (as the mainstream development language) _ DATE_TIME_FORMAT )."";
$ Tables_query = tep_db_query (show tables );
While ($ tables = tep_db_fetch_array ($ tables_query )){
List (, $ table) = each ($ tables );
$ Schema. = drop table if exists. $ table .;."".
Create table. $ table .(."";
$ Table_list = array ();
$ Fields_query = tep_db_query ("show fields from". $ table );
While ($ fields = tep_db_fetch_array ($ fields_query )){
$ Table_list [] = $ fields [Field];
$ Schema. =. $ fields [Field]... $ fields [Type];
If (strlen ($ fields [Default])> 0) $ schema. = default. $ fields [Default].;
If ($ fields [Null]! = YES) $ schema. = not null;
If (isset ($ fields [Extra]) $ schema. =. $ fields [Extra];
$ Schema. = ,."";
}
$ Schema = ereg_replace (", $", $ schema );

// Add the keys
$ Index = array ();
$ Keys_query = tep_db_query ("show keys from". $ table );
While ($ keys = tep_db_fetch_array ($ keys_query )){
$ Kname = $ keys [Key_name];
If (! Isset ($ index [$ kname]) {
$ Index [$ kname] = array (unique =>! $ Keys [Non_unique],
Columns => array ());
}
$ Index [$ kname] [columns] [] = $ keys [Column_name];
}
While (list ($ kname, $ info) = each ($ index )){
$ Schema. = ,."";
$ Columns = implode ($ info [columns],);
If ($ kname = Prima (the most comprehensive VM Management System) RY ){
$ Schema. = Prima (the most comprehensive VM Management System) ry key (. $ columns .);
} Elseif ($ info [unique]) {
$ Schema. = UNIQUE. $ kname. (. $ columns .);
} Else {
$ Schema. = KEY. $ kname. (. $ columns .);
}
}
$ Schema. = "".);."";

// Dump the data
$ Rows_query = tep_db_query ("select". implode (, $ table_list). "from". $ table );
While ($ rows = tep_db_fetch_array ($ rows_query )){
$ Schema_insert = insert into. $ table. (. I

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.