Sunday 15 January 2012

php - What do the "drop table" and "create table" options in this backup script do? -


I need a script to back up the MySQL database I do not have access to cpanel, shell, or phpmyadmin . / P>

I am concerned about the drop table section of this script and why it will be needed. I do not want to modify the database at all, I just need a backup

Here is my code:

  backup_tables ('localhost', 'username', 'password', 'blog'); / * Backup DB or just one table * / Function Backup_tables ($ host, $ user, $ pass, $ name, $ tables = '*') {$ link = mysql_connect ($ host, $ user, $ pass); Mysql_select_db ($ name, $ link); // Receive all tables if ($ tables == '*') {$ tables = array (); $ Result = mysql_query ('Show tab'); While ($ line = mysql_fetch_row ($ result)) {$ table [] = $ line [0]; }} And {$ tables = is_array ($ tables)? $ Table: explosion (',', $ table); } // Forex Currency ($ tables $ table) {$ result = mysql_query ('SELECT * FROM'. $ Table); $ Num_fields = mysql_num_fields ($ results); $ Refund = 'Drop Table' $ Table ';'; $ Row2 = mysql_fetch_row (mysql_query ('Create Table'. $ Table)); $ Refund = "\ N \ n". $ Line 2 [1]. "; \ N \ n"; ($ I = 0; $ i & lt; $ num_fields; $ i ++) {While ($ line = mysql_fetch_row ($ result)) $ $ = 'INSERT INNTO' $ Table For 'value ('; ($ j = 0; $ j & lt; $ num_fields; $ j ++) {$ line [$ j] = add redness ($ line [$ j]); $ line [$ j ] = Ereg_replace ("\ n", "\\ n", $ line [$ j]); if (isset ($ line [$ j])) {$ return. = '' '. $ Row [$ j] . '' '';} Other {$ Return = '""';} If ($ j & lt; ($ num_fields-1)) {$ return. = ',';}} $ Return. "" ; \ N "; }} $ Refund = "\ N \ n \ n"; } // save file $ handle = fopen ('db-backup -'. (-). ('Md5' Fwrite ($ handle, $ refund); fclose ($ handle);}    

This script is generating a file with all commands in the current database.

Once the script is executed, you can create a file in phpmyadmin, "import" and this table If it exists and then insert all the data that was on the table, the backup time

This will not modify anything from the current database

For example, it will create "Export" function in phpmyadmin for a test table:

  - - Database: `test` - - ---------------------------- ---------- ------------------ - Table structure for table `test_table` - If the test table is present then empty table; Create table if not 'test_table` (` id`in (11) No tap, `digits` int (11) no tap) engine = indodi default charge = latin1; - - Enter the value (1, 23), (2, 45) in the data dumping -`test_table` (`id`,` number`) for table `test_table`;   

There is a seriousness of the SQL statement to regenerate the database.

No comments:

Post a Comment