update
[phpmyadmin/crack.git] / tbl_move_copy.php3
blob4bced980832160c968659b01f9e8d02212730de0
1 <?php
2 /* $Id$ */
5 /**
6 * Insert datas from one table to another one
8 * @param string the original insert statement
10 * @global string the database name
11 * @global string the original table name
12 * @global string the target database and table names
13 * @global string the sql query used to copy the data
15 function PMA_myHandler($sql_insert = '')
17 global $db, $table, $target;
18 global $sql_insert_data;
20 $sql_insert = eregi_replace('INSERT INTO (`?)' . $table . '(`?)', 'INSERT INTO ' . $target, $sql_insert);
21 $result = PMA_mysql_query($sql_insert) or PMA_mysqlDie('', $sql_insert, '', $GLOBALS['err_url']);
23 $sql_insert_data .= $sql_insert . ';' . "\n";
24 } // end of the 'PMA_myHandler()' function
27 /**
28 * Gets some core libraries
30 require('./libraries/grab_globals.lib.php3');
31 require('./libraries/common.lib.php3');
34 /**
35 * Defines the url to return to in case of error in a sql statement
37 $err_url = 'tbl_properties.php3'
38 . '?lang=' . $lang
39 . '&amp;convcharset=' . $convcharset
40 . '&amp;server=' . $server
41 . '&amp;db=' . urlencode($db)
42 . '&amp;table=' . urlencode($table);
45 /**
46 * Selects the database to work with
48 PMA_mysql_select_db($db);
51 /**
52 * A target table name has been sent to this script -> do the work
54 if (isset($new_name) && trim($new_name) != '') {
55 $use_backquotes = 1;
56 $asfile = 1;
58 if (get_magic_quotes_gpc()) {
59 if (!empty($target_db)) {
60 $target_db = stripslashes($target_db);
61 } else {
62 $target_db = stripslashes($db);
64 $new_name = stripslashes($new_name);
67 // Ensure the target is valid
68 if (count($dblist) > 0 &&
69 (PMA_isInto($db, $dblist) == -1 || PMA_isInto($target_db, $dblist) == -1)) {
70 exit();
72 if (PMA_MYSQL_INT_VERSION < 32306) {
73 PMA_checkReservedWords($target_db, $err_url);
74 PMA_checkReservedWords($new_name, $err_url);
77 $source = PMA_backquote($db) . '.' . PMA_backquote($table);
78 $target = PMA_backquote($target_db) . '.' . PMA_backquote($new_name);
80 include('./libraries/build_dump.lib.php3');
82 $sql_structure = PMA_getTableDef($db, $table, "\n", $err_url);
83 $sql_structure = eregi_replace('^CREATE TABLE (`?)' . $table . '(`?)', 'CREATE TABLE ' . $target, $sql_structure);
84 $result = @PMA_mysql_query($sql_structure);
85 if (PMA_mysql_error()) {
86 include('./header.inc.php3');
87 PMA_mysqlDie('', $sql_structure, '', $err_url);
88 } else if (isset($sql_query)) {
89 $sql_query .= "\n" . $sql_structure . ';';
90 } else {
91 $sql_query = $sql_structure . ';';
94 // Copy the data
95 if ($result != FALSE && $what == 'data') {
96 // speedup copy table - staybyte - 22. Juni 2001
97 if (PMA_MYSQL_INT_VERSION >= 32300) {
98 $sql_insert_data = 'INSERT INTO ' . $target . ' SELECT * FROM ' . $source;
99 $result = @PMA_mysql_query($sql_insert_data);
100 if (PMA_mysql_error()) {
101 include('./header.inc.php3');
102 PMA_mysqlDie('', $sql_insert_data, '', $err_url);
104 } // end MySQL >= 3.23
105 else {
106 $sql_insert_data = '';
107 PMA_getTableContent($db, $table, 0, 0, 'PMA_myHandler', $err_url);
108 } // end MySQL < 3.23
109 $sql_query .= "\n\n" . $sql_insert_data;
112 // Drops old table if the user has requested to move it
113 if (isset($submit_move)) {
114 $sql_drop_table = 'DROP TABLE ' . $source;
115 $result = @PMA_mysql_query($sql_drop_table);
116 if (PMA_mysql_error()) {
117 include('./header.inc.php3');
118 PMA_mysqlDie('', $sql_drop_table, '', $err_url);
120 $sql_query .= "\n\n" . $sql_drop_table . ';';
121 $db = $target_db;
122 $table = $new_name;
125 $message = (isset($submit_move) ? $strMoveTableOK : $strCopyTableOK);
126 $message = sprintf($message, $source, $target);
127 $reload = 1;
128 $js_to_run = 'functions.js';
129 include('./header.inc.php3');
130 } // end is target table name
134 * No new name for the table!
136 else {
137 include('./header.inc.php3');
138 PMA_mysqlDie($strTableEmpty, '', '', $err_url);
143 * Back to the calling script
145 require('./tbl_properties.php3');