*** empty log message ***
[phpmyadmin/crack.git] / tbl_copy.php3
blob360c5809585b7f0f150c14b0cdc2bf14e933fcbb
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 my_handler($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 mysql_die('', $sql_insert);
23 $sql_insert_data .= $sql_insert . ';' . "\n";
24 } // end of the 'my_handler' function
27 /**
28 * Gets some core libraries
30 require('./grab_globals.inc.php3');
31 require('./header.inc.php3');
34 /**
35 * Selects the database to work with
37 mysql_select_db($db);
40 /**
41 * A target table name has been sent to this script -> do the work
43 if (isset($new_name) && trim($new_name) != '') {
44 $use_backquotes = 1;
45 $asfile = 1;
47 if (get_magic_quotes_gpc()) {
48 if (!empty($target_db)) {
49 $target_db = stripslashes($target_db);
50 } else {
51 $target_db = stripslashes($db);
53 $new_name = stripslashes($new_name);
55 $source = backquote($db) . '.' . backquote($table);
56 $target = backquote($target_db) . '.' . backquote($new_name);
58 $sql_structure = get_table_def($db, $table, "\n");
59 $sql_structure = eregi_replace('^CREATE TABLE (`?)' . $table . '(`?)', 'CREATE TABLE ' . $target, $sql_structure);
60 $result = mysql_query($sql_structure) or mysql_die('', $sql_structure);
61 if (isset($sql_query)) {
62 $sql_query .= "\n" . $sql_structure . ';';
63 } else {
64 $sql_query = $sql_structure . ';';
67 // Copy the data
68 if ($result != FALSE && $what == 'data') {
69 // speedup copy table - staybyte - 22. Juni 2001
70 if (MYSQL_INT_VERSION >= 32300) {
71 $sql_insert_data = 'INSERT INTO ' . $target . ' SELECT * FROM ' . backquote($table);
72 $result = mysql_query($sql_insert_data) or mysql_die('', $sql_insert_data);
73 } // end MySQL >= 3.23
74 else {
75 $sql_insert_data = '';
76 get_table_content($db, $table, 0, 0, 'my_handler');
77 } // end MySQL < 3.23
78 $sql_query .= "\n\n" . $sql_insert_data;
81 $message = sprintf($strCopyTableOK, $source, $target);
82 $reload = 'true';
83 } // end is target table name
86 /**
87 * No new name for the table!
89 else {
90 mysql_die($strTableEmpty);
94 /**
95 * Back to the calling script
97 require('./tbl_properties.php3');