3 // vim: expandtab sw=4 ts=4 sts=4:
6 * Insert data 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
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 . '&convcharset=' . $convcharset
40 . '&server=' . $server
41 . '&db=' . urlencode($db)
42 . '&table=' . urlencode($table);
46 * Selects the database to work with
48 PMA_mysql_select_db($db);
52 * A target table name has been sent to this script -> do the work
54 if (isset($new_name) && trim($new_name) != '') {
58 if (get_magic_quotes_gpc()) {
59 if (!empty($target_db)) {
60 $target_db = stripslashes($target_db);
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)) {
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 $parsed_sql = PMA_SQP_parse($sql_structure);
84 // no need to PMA_backquote()
85 $parsed_sql[2]['data'] = $target;
86 $sql_structure = PMA_SQP_formatHtml($parsed_sql, 'query_only');
88 // do not create the table if dataonly
89 if ($what != 'dataonly') {
90 $result = @PMA_mysql_query
($sql_structure);
91 if (PMA_mysql_error()) {
92 include('./header.inc.php3');
93 PMA_mysqlDie('', $sql_structure, '', $err_url);
94 } else if (isset($sql_query)) {
95 $sql_query .= "\n" . $sql_structure . ';';
97 $sql_query = $sql_structure . ';';
104 if ($result != FALSE && ($what == 'data' ||
$what == 'dataonly')) {
105 // speedup copy table - staybyte - 22. Juni 2001
106 if (PMA_MYSQL_INT_VERSION
>= 32300) {
107 $sql_insert_data = 'INSERT INTO ' . $target . ' SELECT * FROM ' . $source;
108 $result = @PMA_mysql_query
($sql_insert_data);
109 if (PMA_mysql_error()) {
110 include('./header.inc.php3');
111 PMA_mysqlDie('', $sql_insert_data, '', $err_url);
113 } // end MySQL >= 3.23
115 $sql_insert_data = '';
116 PMA_getTableContent($db, $table, 0, 0, 'PMA_myHandler', $err_url);
117 } // end MySQL < 3.23
118 $sql_query .= "\n\n" . $sql_insert_data;
121 // Drops old table if the user has requested to move it
122 if (isset($submit_move)) {
123 $sql_drop_table = 'DROP TABLE ' . $source;
124 $result = @PMA_mysql_query
($sql_drop_table);
125 if (PMA_mysql_error()) {
126 include('./header.inc.php3');
127 PMA_mysqlDie('', $sql_drop_table, '', $err_url);
129 $sql_query .= "\n\n" . $sql_drop_table . ';';
134 $message = (isset($submit_move) ?
$strMoveTableOK : $strCopyTableOK);
135 $message = sprintf($message, $source, $target);
137 $js_to_run = 'functions.js';
138 include('./header.inc.php3');
139 } // end is target table name
143 * No new name for the table!
146 include('./header.inc.php3');
147 PMA_mysqlDie($strTableEmpty, '', '', $err_url);
152 * Back to the calling script
154 require('./tbl_properties.php3');