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 = 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
28 * Gets some core libraries
30 require('./libraries/grab_globals.lib.php3');
31 require('./libraries/common.lib.php3');
35 * Defines the url to return to in case of error in a sql statement
37 $err_url = 'tbl_properties.php3'
39 . '&server=' . $server
40 . '&db=' . urlencode($db)
41 . '&table=' . urlencode($table);
45 * Selects the database to work with
51 * A target table name has been sent to this script -> do the work
53 if (isset($new_name) && trim($new_name) != '') {
57 if (get_magic_quotes_gpc()) {
58 if (!empty($target_db)) {
59 $target_db = stripslashes($target_db);
61 $target_db = stripslashes($db);
63 $new_name = stripslashes($new_name);
66 // Ensure the target is valid
67 if (count($dblist) > 0 &&
68 (PMA_isInto($db, $dblist) == -1 ||
PMA_isInto($target_db, $dblist) == -1)) {
71 if (PMA_MYSQL_INT_VERSION
< 32306) {
72 PMA_checkReservedWords($target_db, $err_url);
73 PMA_checkReservedWords($new_name, $err_url);
76 $source = PMA_backquote($db) . '.' . PMA_backquote($table);
77 $target = PMA_backquote($target_db) . '.' . PMA_backquote($new_name);
79 include('./libraries/build_dump.lib.php3');
81 $sql_structure = PMA_getTableDef($db, $table, "\n", $err_url);
82 $sql_structure = eregi_replace('^CREATE TABLE (`?)' . $table . '(`?)', 'CREATE TABLE ' . $target, $sql_structure);
83 $result = @mysql_query
($sql_structure);
85 include('./header.inc.php3');
86 PMA_mysqlDie('', $sql_structure, '', $err_url);
87 } else if (isset($sql_query)) {
88 $sql_query .= "\n" . $sql_structure . ';';
90 $sql_query = $sql_structure . ';';
94 if ($result != FALSE && $what == 'data') {
95 // speedup copy table - staybyte - 22. Juni 2001
96 if (PMA_MYSQL_INT_VERSION
>= 32300) {
97 $sql_insert_data = 'INSERT INTO ' . $target . ' SELECT * FROM ' . $source;
98 $result = @mysql_query
($sql_insert_data);
100 include('./header.inc.php3');
101 PMA_mysqlDie('', $sql_insert_data, '', $err_url);
103 } // end MySQL >= 3.23
105 $sql_insert_data = '';
106 PMA_getTableContent($db, $table, 0, 0, 'PMA_myHandler', $err_url);
107 } // end MySQL < 3.23
108 $sql_query .= "\n\n" . $sql_insert_data;
111 // Drops old table if the user has requested to move it
112 if (isset($submit_move)) {
113 $sql_drop_table = 'DROP TABLE ' . $source;
114 $result = @mysql_query
($sql_drop_table);
116 include('./header.inc.php3');
117 PMA_mysqlDie('', $sql_drop_table, '', $err_url);
119 $sql_query .= "\n\n" . $sql_drop_table . ';';
124 $message = (isset($submit_move) ?
$strMoveTableOK : $strCopyTableOK);
125 $message = sprintf($message, $source, $target);
127 $js_to_run = 'functions.js';
128 include('./header.inc.php3');
129 } // end is target table name
133 * No new name for the table!
136 include('./header.inc.php3');
137 PMA_mysqlDie($strTableEmpty, '', '', $err_url);
142 * Back to the calling script
144 require('./tbl_properties.php3');