Exemplo n.º 1
0
 /**
  * Adds backquotes on both sides of a database, table or field name.
  * and escapes backquotes inside the name with another backquote
  *
  * example:
  * <code>
  * echo backquote('owner`s db'); // `owner``s db`
  *
  * </code>
  *
  * @param mixed   $a_name the database, table or field name to "backquote"
  *                        or array of it
  * @param boolean $do_it  a flag to bypass this function (used by dump
  *                        functions)
  *
  * @return  mixed    the "backquoted" database, table or field name
  *
  * @access  public
  */
 static function backquote($a_name)
 {
     if (is_array($a_name)) {
         foreach ($a_name as &$data) {
             $data = backquote($data);
         }
         return $a_name;
     }
     // '0' is also empty for php :-(
     if (strlen($a_name) && $a_name !== '*') {
         return '`' . str_replace('`', '``', $a_name) . '`';
     } else {
         return $a_name;
     }
 }
Exemplo n.º 2
0
 }
 $formatted_db_name = isset($use_backquotes) ? backquote($db) : '\'' . $db . '\'';
 $dump_buffer .= $crlf . '# ' . $strGenTime . ': ' . date('F j, Y, g:i a') . $crlf . '# ' . $strServerVersion . ': ' . substr(MYSQL_INT_VERSION, 0, 1) . '.' . substr(MYSQL_INT_VERSION, 1, 2) . '.' . substr(MYSQL_INT_VERSION, 3) . $crlf . '# ' . $strPHPVersion . ': ' . phpversion() . $crlf . '# ' . $strDatabase . ': ' . $formatted_db_name . $crlf;
 $i = 0;
 if (isset($table_select)) {
     $tmp_select = implode($table_select, '|');
     $tmp_select = '|' . $tmp_select . '|';
 }
 while ($i < $num_tables) {
     if (!isset($single)) {
         $table = mysql_tablename($tables, $i);
     }
     if (isset($tmp_select) && is_int(strpos($tmp_select, '|' . $table . '|')) == FALSE) {
         $i++;
     } else {
         $formatted_table_name = isset($use_backquotes) ? backquote($table) : '\'' . $table . '\'';
         // If only datas, no need to displays table name
         if ($what != 'dataonly') {
             $dump_buffer .= '# --------------------------------------------------------' . $crlf . $crlf . '#' . $crlf . '# ' . $strTableStructure . ' ' . $formatted_table_name . $crlf . '#' . $crlf . $crlf . get_table_def($db, $table, $crlf) . ';' . $crlf;
         }
         // At least data
         if ($what == 'data' || $what == 'dataonly') {
             $dump_buffer .= $crlf . '#' . $crlf . '# ' . $strDumpingData . ' ' . $formatted_table_name . $crlf . '#' . $crlf . $crlf;
             $tmp_buffer = '';
             if (!isset($limit_from) || !isset($limit_to)) {
                 $limit_from = $limit_to = 0;
             }
             get_table_content($db, $table, $limit_from, $limit_to, 'my_handler');
             $dump_buffer .= $tmp_buffer;
         }
         // end if
Exemplo n.º 3
0
function make_sql($table, $sql_drop_table = true)
{
    /*
    	Reads the Database table in $table and creates
    	SQL Statements for recreating structure and data
    */
    $sql_statements = "";
    // Add SQL statement to drop existing table
    /*
    		//$sql_statements .= "\n";
    		$sql_statements .= "\n";
    		$sql_statements .= "#\n";
    		$sql_statements .= "# Delete any existing table " . backquote($table) . "\n";
    		$sql_statements .= "#\n";
    		//$sql_statements .= "\n";*/
    if ($sql_drop_table) {
        $sql_statements .= "DROP TABLE IF EXISTS " . backquote($table) . ";\n";
    }
    // Table structure
    // Comment in SQL-file
    //$sql_statements .= "\n";
    //$sql_statements .= "\n";
    //$sql_statements .= "#\n";
    //$sql_statements .= "# Table structure of table " . backquote($table) . "\n";
    //$sql_statements .= "#\n";
    //$sql_statements .= "\n";
    // Get table structure
    $query = "SHOW CREATE TABLE " . backquote($table);
    $result = mysql_query($query, $GLOBALS["db_connect"]);
    if ($result == FALSE) {
        log_msg(date("H:i:s") . ": Error getting table structure of {$table}!\n", 20);
        log_msg("          " . mysql_errno() . ": " . mysql_error() . "\n", 20);
    } else {
        if (mysql_num_rows($result) > 0) {
            $sql_create_arr = mysql_fetch_array($result);
            $sql_statements .= $sql_create_arr[1];
        }
        mysql_free_result($result);
        $sql_statements .= " ;";
    }
    // ($result == FALSE)
    // Table data contents
    // Get table contents
    $query = "SELECT * FROM " . backquote($table);
    $result = mysql_query($query, $GLOBALS["db_connect"]);
    if ($result == FALSE) {
        log_msg(date("H:i:s") . ": Error getting records of {$table}!\n", 30);
        log_msg("          " . mysql_errno() . ": " . mysql_error() . "\n", 30);
    } else {
        $fields_cnt = mysql_num_fields($result);
        $rows_cnt = mysql_num_rows($result);
    }
    // if ($result == FALSE)
    // Comment in SQL-file
    //$sql_statements .= "\n";
    //$sql_statements .= "\n";
    //$sql_statements .= "#\n";
    $sql_statements .= "# Data contents of table " . $table . " (" . $rows_cnt . " records)\n";
    //$sql_statements .= "#\n";
    // Checks whether the field is an integer or not
    for ($j = 0; $j < $fields_cnt; $j++) {
        $field_set[$j] = backquote(mysql_field_name($result, $j));
        $type = mysql_field_type($result, $j);
        if ($type == 'tinyint' || $type == 'smallint' || $type == 'mediumint' || $type == 'int' || $type == 'bigint') {
            $field_num[$j] = TRUE;
        } else {
            $field_num[$j] = FALSE;
        }
    }
    // end for
    // Sets the scheme
    $_entries = 'INSERT INTO ' . backquote($table) . ' VALUES';
    $sql_statements .= "\n" . $_entries;
    $entries = "\n (";
    $search = array("", "\n", "\r", "");
    //\x08\\x09, not required
    $replace = array('\\0', '\\n', '\\r', '\\Z');
    $current_row = 0;
    $_entries_count = 0;
    while ($row = mysql_fetch_row($result)) {
        $current_row++;
        for ($j = 0; $j < $fields_cnt; $j++) {
            if (!isset($row[$j])) {
                $values[] = 'NULL';
            } else {
                if ($row[$j] == '0' || $row[$j] != '') {
                    // a number
                    if ($field_num[$j]) {
                        $values[] = $row[$j];
                    } else {
                        $values[] = "'" . str_replace($search, $replace, sql_addslashes($row[$j])) . "'";
                    }
                    //if ($field_num[$j])
                } else {
                    $values[] = "''";
                }
            }
            // if (!isset($row[$j]))
        }
        // for ($j = 0; $j < $fields_cnt; $j++)
        $sql_statements .= $entries . implode(', ', $values) . ')';
        $_entries_count++;
        //break in processes of 100 rows
        if ($_entries_count % 100 == 0) {
            $sql_statements .= ";\n" . $_entries;
        } else {
            $sql_statements .= ",";
        }
        unset($values);
    }
    // while ($row = mysql_fetch_row($result))
    mysql_free_result($result);
    if (endsWith($sql_statements, ",")) {
        $sql_statements = substr($sql_statements, 0, strlen($sql_statements) - 1);
    } else {
        if (endsWith($sql_statements, $_entries)) {
            $sql_statements = substr($sql_statements, 0, strlen($sql_statements) - strlen($_entries));
        }
    }
    $sql_statements .= ";\n";
    // Create footer/closing comment in SQL-file
    //$sql_statements .= "\n";
    //$sql_statements .= "#\n";
    //$sql_statements .= "# End of data contents of table " . $table . "\n";
    //$sql_statements .= "# --------------------------------------------------------\n";
    //$sql_statements .= "\n";
    return $sql_statements;
}
Exemplo n.º 4
0
 }
 if (strlen($escaped) > 0) {
     $query .= ' ESCAPED BY \'' . $escaped . '\'';
 }
 if (strlen($line_terminator) > 0) {
     $query .= ' LINES TERMINATED BY \'' . $line_terminator . '\'';
 }
 if (strlen($column_name) > 0) {
     if (MYSQL_INT_VERSION >= 32306) {
         $query .= ' (';
         $tmp = split(',( ?)', $column_name);
         for ($i = 0; $i < count($tmp); $i++) {
             if ($i > 0) {
                 $query .= ', ';
             }
             $query .= backquote(trim($tmp[$i]));
         }
         // end for
         $query .= ')';
     } else {
         $query .= ' (' . $column_name . ')';
     }
 }
 // Executes the query
 // sql.php will stripslash the query if 'magic_quotes_gpc' is set to on
 if (get_magic_quotes_gpc()) {
     $sql_query = addslashes($query);
 } else {
     $sql_query = $query;
 }
 include './sql.php';
Exemplo n.º 5
0
            $query .= ' DEFAULT \'' . sql_addslashes($field_default[0]) . '\'';
        }
    }
    if ($field_null[0] != '') {
        $query .= ' ' . $field_null[0];
    }
    if ($field_extra[0] != '') {
        $query .= ' ' . $field_extra[0];
    }
    // Optimization fix - 2 May 2001 - Robbat2
    $sql_query = 'ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' CHANGE ' . $query;
    $result = mysql_query($sql_query) or mysql_die();
    $message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenAltered;
    include './tbl_properties.php';
    exit;
} else {
    if (get_magic_quotes_gpc()) {
        $field = sql_addslashes(stripslashes($field), TRUE);
    } else {
        $field = sql_addslashes($field, TRUE);
    }
    $local_query = 'SHOW FIELDS FROM ' . backquote($db) . '.' . backquote($table) . " LIKE '{$field}'";
    $result = mysql_query($local_query) or mysql_die('', $local_query);
    $num_fields = mysql_num_rows($result);
    $action = 'tbl_alter.php';
    include './tbl_properties.inc.php';
}
/**
 * Displays the footer
 */
require './footer.inc.php';
Exemplo n.º 6
0
    }
    $source = backquote($db) . '.' . backquote($table);
    $target = backquote($target_db) . '.' . backquote($new_name);
    $sql_structure = get_table_def($db, $table, "\n");
    $sql_structure = eregi_replace('^CREATE TABLE (`?)' . $table . '(`?)', 'CREATE TABLE ' . $target, $sql_structure);
    $result = mysql_query($sql_structure) or mysql_die('', $sql_structure);
    if (isset($sql_query)) {
        $sql_query .= "\n" . $sql_structure . ';';
    } else {
        $sql_query = $sql_structure . ';';
    }
    // Copy the data
    if ($result != FALSE && $what == 'data') {
        // speedup copy table - staybyte - 22. Juni 2001
        if (MYSQL_INT_VERSION >= 32300) {
            $sql_insert_data = 'INSERT INTO ' . $target . ' SELECT * FROM ' . backquote($table);
            $result = mysql_query($sql_insert_data) or mysql_die('', $sql_insert_data);
        } else {
            $sql_insert_data = '';
            get_table_content($db, $table, 0, 0, 'my_handler');
        }
        // end MySQL < 3.23
        $sql_query .= "\n\n" . $sql_insert_data;
    }
    $message = sprintf($strCopyTableOK, $source, $target);
    $reload = 'true';
} else {
    mysql_die($strTableEmpty);
}
/**
 * Back to the calling script
Exemplo n.º 7
0
<?php

/* $Id: db_create.php,v 1.8 2001/08/22 20:42:51 loic1 Exp $ */
/**
 * Gets some core libraries
 */
require './grab_globals.inc.php';
require './header.inc.php';
/**
 * Executes the db creation sql query
 */
$local_query = 'CREATE DATABASE ' . backquote($db);
$result = mysql_query('CREATE DATABASE ' . backquote($db)) or mysql_die('', $local_query, FALSE);
/**
 * Displays the result and moves back to the calling page
 */
$message = $strDatabase . ' ' . htmlspecialchars($db) . ' ' . $strHasBeenCreated;
require './db_details.php';
Exemplo n.º 8
0
                        } else {
                            if (strstr($fields[$i], '%')) {
                                $quot = '\'';
                                $cmp = 'LIKE';
                            } else {
                                if (substr($fields[$i], 0, 1) == '<' || substr($fields[$i], 0, 1) == '>') {
                                    $quot = '';
                                    $cmp = '';
                                } else {
                                    $quot = '';
                                    $cmp = '=';
                                }
                            }
                        }
                    }
                }
                // end if
                $sql_query .= ' AND ' . backquote(urldecode($names[$i])) . " {$cmp} {$quot}{$fields[$i]}{$quot}";
            }
            // end if
        }
        // end for
    }
    // end if
    if ($orderField != '--nil--') {
        $sql_query .= ' ORDER BY ' . backquote(urldecode($orderField)) . ' ' . $order;
    }
    // end if
    $url_query = 'lang=' . $lang . '&server=' . $server . '&db=' . urlencode($db) . '&table=' . urlencode($table) . '&sql_query=' . urlencode($sql_query) . '&pos=0' . '&sessionMaxRows=' . $sessionMaxRows . '&goto=' . $goto;
    header('Location: ' . $cfgPmaAbsoluteUri . 'sql.php?' . $url_query);
}
Exemplo n.º 9
0
    }
    if (!empty($primary_key)) {
        $primary_key = stripslashes($primary_key);
    }
}
/**
 * Get the list of the fields of the current table
 */
mysql_select_db($db);
$table_def = mysql_query('SHOW FIELDS FROM ' . backquote($table));
if (isset($primary_key)) {
    $local_query = 'SELECT * FROM ' . backquote($table) . ' WHERE ' . $primary_key;
    $result = mysql_query($local_query) or mysql_die('', $local_query);
    $row = mysql_fetch_array($result);
} else {
    $local_query = 'SELECT * FROM ' . backquote($table) . ' LIMIT 1';
    $result = mysql_query($local_query) or mysql_die('', $local_query);
}
/**
 * Displays the form
 */
?>

<!-- Change table properties form -->
<form method="post" action="tbl_replace.php">
    <input type="hidden" name="server" value="<?php 
echo $server;
?>
" />
    <input type="hidden" name="lang" value="<?php 
echo $lang;
Exemplo n.º 10
0
 /**
  * Deletes a bookmark
  *
  * @param   string   the current database name
  * @param   array    the bookmark parameters for the current user
  * @param   integer  the id of the bookmark to get
  */
 function delete_bookmarks($db, $cfgBookmark, $id)
 {
     $query = 'DELETE FROM ' . backquote($cfgBookmark['db']) . '.' . backquote($cfgBookmark['table']) . ' WHERE user = \'' . sql_addslashes($cfgBookmark['user']) . '\'' . ' AND id = ' . $id;
     if (isset($GLOBALS['dbh'])) {
         $result = mysql_query($query, $GLOBALS['dbh']);
     } else {
         $result = mysql_query($query);
     }
 }
Exemplo n.º 11
0
function grant_operations()
{
    global $server, $lang, $user, $host;
    global $dbgrant, $tablegrant;
    global $self;
    global $strBack, $strGo;
    global $strDbEmpty, $strTableEmpty;
    global $strAddPriv, $strAddPrivMessage;
    global $strDatabase, $strAnyDatabase;
    global $strTable, $strAnyTable;
    global $strColumn, $strAnyColumn, $strColumnEmpty;
    global $strPrivileges;
    ?>

    <script language="JavaScript">
    <!--

    function getSelected(field) {
        var f = "";
        for (var i = 0; i < field.options.length; i++)
          if (field.options[i].selected)
              f += field.options[i].text + ", ";

        return f.substring(0, f.length - 2);
    }

    function addGrant(f) {
        var sql;
        var db, table, column = "";

        db = getSelected(f.database);
        table = getSelected(f.table);
        column = getSelected(f.column);

        if (f.anydb[1].checked) {

            if (db == "") {
               alert("<?php 
    echo $strDbEmpty;
    ?>
");
               return;
            }

            if (f.anytable[1].checked) {

               if (table == "") {
                  alert("<?php 
    echo $strTableEmpty;
    ?>
");
                  return;
               }

               if (f.anycolumn[1].checked) {
                  if (column == "") {
                     alert("<?php 
    echo $strColumnEmpty;
    ?>
");
                     return;
                  }
                  column = " (" + column + ")";

               } else column = "";

            } else {table = "*"; column = ""; }

        } else { db = "*"; table = "*"; column = ""; }

        sql = "GRANT " + privGrantToString(f) + "" + column;
        sql += " ON " + protect_name(db) + "." + protect_name(table) 
        sql += " TO '" + "<?php 
    echo $user;
    ?>
" + "'@'" + "<?php 
    echo $host;
    ?>
'"
        if (f.Grant_priv.checked) sql += " with grant option";

        url  = "sql.php";
        url += "?sql_query=" + escape(sql);
        url += "&zero_rows=" + escape("<?php 
    echo $strAddPrivMessage;
    ?>
");
        url += "<?php 
    echo "&server={$server}&lang={$lang}";
    ?>
&db=mysql";
        url += "&goto=<?php 
    echo $self;
    ?>
";

        location.href = url;
    }

    function protect_name(db_or_table) {
	var js_mysql_version = <?php 
    echo MYSQL_INT_VERSION;
    ?>
;

	if (js_mysql_version >= 32306) {
<!--		return "`" + db_or_table + "`"; -->
		return db_or_table;
	}
	else {
		return db_or_table;
	}
    }

    function change(f, param) {
        var l, p;

        l = location.href;
        if (param == "dbgrant") {
           p = l.indexOf("&" + param);
           if ( p >= 0) l = l.substring(0, p);
        }

        location.href = l + "&" + param + "=" + getSelected(f);
    }

    // -->
    </script>

    <div align=left>
    <ul>

    <li><a href="<?php 
    echo "{$self}?server={$server}&lang={$lang}&db=mysql&table=user";
    ?>
"><?php 
    echo $strBack;
    ?>
</a></li>

    <li><form name=userForm3 onsubmit ="return false"><?php 
    echo $strAddPriv;
    ?>
    <table width="100%"><tr>
    <td><input type="radio" name="anydb"<?php 
    echo $dbgrant ? "" : " checked";
    ?>
><?php 
    echo $strAnyDatabase;
    ?>
</td>
    <td>&nbsp;</td>
    <td><input type="radio" name="anydb"<?php 
    echo $dbgrant ? " checked" : "";
    ?>
><?php 
    echo $strDatabase;
    ?>
:&nbsp;
    <select name="database" onchange="change(userForm3.database, 'dbgrant')">
<?php 
    if (!isset($dbgrant)) {
        echo "<option selected></option>";
    }
    $result = mysql_query("SHOW DATABASES");
    if (@mysql_num_rows($result)) {
        while ($row = mysql_fetch_row($result)) {
            $selected = $row[0] == $dbgrant ? "SELECTED" : "";
            echo "<option {$selected}>" . $row[0] . "</option>\n";
        }
    }
    ?>
    </select></td>
    </tr></table>

    <table width="100%"><tr>
    <td><input type="radio" name="anytable"<?php 
    echo $tablegrant ? "" : " checked";
    ?>
><?php 
    echo $strAnyTable;
    ?>
</td>
    <td>&nbsp;</td>
    <td><input type="radio" name="anytable"<?php 
    echo $tablegrant ? " checked" : "";
    ?>
><?php 
    echo $strTable;
    ?>
:&nbsp;
    <select name="table" onchange="change(userForm3.table, 'tablegrant')"
    >
<?php 
    if (isset($dbgrant)) {
        if (!isset($tablegrant)) {
            echo "<option selected></option>";
        }
        $result = mysql_query("SHOW TABLES from " . backquote($dbgrant));
        if (@mysql_num_rows($result)) {
            while ($row = mysql_fetch_row($result)) {
                $selected = $row[0] == $tablegrant ? "SELECTED" : "";
                echo "<option {$selected}>" . $row[0] . "</option>\n";
            }
        }
    }
    ?>
    </select></td>
    </tr></table>

    <table width="100%"><tr>
    <td VALIGN=TOP><input type="radio" name="anycolumn" checked><?php 
    echo $strAnyColumn;
    ?>
</td>
    <td>&nbsp;</td>
    <td VALIGN=TOP><input type="radio" name="anycolumn"><?php 
    echo $strColumn;
    ?>
:</td>
    <td>
    <select name="column" onchange="anycolumn[1].checked = true" multiple>
<?php 
    if (isset($dbgrant) && isset($tablegrant)) {
        $result = mysql_query("SHOW COLUMNS FROM " . backquote($dbgrant) . "." . backquote($tablegrant));
        if (@mysql_num_rows($result)) {
            while ($row = mysql_fetch_row($result)) {
                echo "<option>" . $row[0] . "</option>\n";
            }
        }
    }
    ?>
    </select>
    </td>
    </tr></table>

    <table><tr><td><br><?php 
    echo $strPrivileges;
    ?>
:<br></td></tr></table>
    <?php 
    table_privileges("userForm3");
    ?>
    <input type="button" value="<?php 
    echo $strGo;
    ?>
" onclick="addGrant(userForm3)"></p>
    </form>
    </li>
    </ul>
    </div>
    <?php 
}
Exemplo n.º 12
0
 $big_tot_data = 0;
 $results_array = array();
 // Gets and displays the tables stats per database
 for ($i = 0; $i < $num_dbs; $i++) {
     $db = $dblist[$i];
     $j = $i + 2;
     $bgcolor = $i % 2 ? $cfgBgcolorOne : $cfgBgcolorTwo;
     if (!empty($db_start) && $db == $db_start) {
         $selected_db = $j;
     }
     $tables = @mysql_list_tables($db);
     $num_tables = @mysql_numrows($tables);
     $tot_tables += $num_tables;
     $common_url_query = 'lang=' . $lang . '&server=' . $server . '&db=' . urlencode($db);
     // Gets size of data and indexes
     $db_clean = backquote($db);
     $tot_data = 0;
     $tot_idx = 0;
     $tot_all = 0;
     $local_query = 'SHOW TABLE STATUS FROM ' . $db_clean;
     $result = @mysql_query($local_query);
     if (@mysql_num_rows($result)) {
         // needs the "@": otherwise, warnings in case of special DB names:
         // Warning: Supplied argument is not a valid MySQL result resource in db_stats.php on line 140
         while ($row = mysql_fetch_array($result)) {
             $tot_data += $row['Data_length'];
             $tot_idx += $row['Index_length'];
         }
         $tot_all = $tot_data + $tot_idx;
         $big_tot_all += $tot_all;
         $big_tot_idx += $tot_idx;
Exemplo n.º 13
0
<?php

/* $Id: tbl_rename.php,v 1.7 2001/08/22 20:42:51 loic1 Exp $ */
/**
 * Gets some core libraries
 */
require './grab_globals.inc.php';
require './lib.inc.php';
/**
 * A new name has been submitted -> do the work
 */
if (isset($new_name) && trim($new_name) != '') {
    $old_name = $table;
    $table = $new_name;
    include './header.inc.php';
    mysql_select_db($db);
    $local_query = 'ALTER TABLE ' . backquote($old_name) . ' RENAME ' . backquote($new_name);
    $result = mysql_query($local_query) or mysql_die('', $local_query);
    $message = sprintf($strRenameTableOK, $old_name, $table);
    $reload = 'true';
} else {
    include './header.inc.php';
    mysql_die($strTableEmpty);
}
/**
 * Back to the calling script
 */
require './tbl_properties.php';
Exemplo n.º 14
0
                 close_daily($fp, $keep_days);
                 // Do we have to do a weekly backup? (separate sql-file for every table)
                 if (date("w") == $weekday) {
                     weekly_backup($fname, $keep_weeks);
                 }
                 // if (date("w") ...
                 // Do we have to do a monthly backup? (separate sql-file for every table)
                 if (date("j") == date("t") or date("j") == $monthday) {
                     monthly_backup($fname, $keep_months);
                 }
                 // if ((date("j") ...
             }
             // if ($fp = open_daily($fname))
         } else {
             $sql_file .= "# --------------------------------------------------------\n";
             $sql_file .= "# Table: " . backquote($curr_table) . "\n";
             $sql_file .= "# --------------------------------------------------------\n";
             $sql_file .= $sql_statements;
         }
         // if ($db_backup_sql_single_file == FALSE)
         log_msg(date("H:i:s") . ": Backup of table {$db_name}.{$curr_table} finished.\n");
     } else {
         log_msg(date("H:i:s") . ": Table {$curr_table} is excluded from backup.\n");
     }
     // if (!in_array($curr_table, $exclude_tables))
     log_msg($sep);
 }
 // for ($i = 0; $i < mysql_num_rows($tables); $i++)
 $sql_file .= $file_footer;
 // Do we use only one single sql-file for all tables?
 if ($sql_single_file) {
Exemplo n.º 15
0
if (!empty($qry_select)) {
    $encoded_qry .= urlencode('SELECT ' . $qry_select . "\n");
    echo 'SELECT ' . htmlspecialchars($qry_select) . "\n";
}
// 2. FROM
if (!isset($TableList)) {
    $TableList = array();
}
if (!isset($qry_from)) {
    $qry_from = '';
}
for ($x = 0; $x < sizeof($TableList); $x++) {
    if ($x) {
        $qry_from .= ', ';
    }
    $qry_from .= backquote(urldecode($TableList[$x]));
}
// end for
if (!empty($qry_from)) {
    $encoded_qry .= urlencode('FROM ' . $qry_from . "\n");
    echo 'FROM ' . htmlspecialchars($qry_from) . "\n";
}
// 3. WHERE
$qry_where = '';
$criteria_cnt = 0;
for ($x = 0; $x < $col; $x++) {
    if (!empty($curField[$x]) && !empty($curCriteria[$x]) && $x && isset($last_where)) {
        $qry_where .= ' ' . strtoupper($curAndOrCol[$last_where]) . ' ';
    }
    if (!empty($curField[$x]) && !empty($curCriteria[$x])) {
        $qry_where .= '(' . $curField[$x] . ' ' . $curCriteria[$x] . ')';
Exemplo n.º 16
0
            $sql_query .= "\n" . 'ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' ADD INDEX (' . $index . ')';
            $result = mysql_query('ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' ADD INDEX (' . $index . ')') or mysql_die();
        }
    }
    // end if
    // Builds the uniques statements and updates the table
    $unique = '';
    if (isset($field_unique)) {
        for ($i = 0; $i < count($field_unique); $i++) {
            $j = $field_unique[$i];
            $unique .= backquote($field_name[$j]) . ', ';
        }
        // end for
        $unique = ereg_replace(', $', '', $unique);
        if (!empty($unique)) {
            $sql_query .= "\n" . 'ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' ADD UNIQUE (' . $unique . ')';
            $result = mysql_query('ALTER TABLE ' . backquote($db) . '.' . backquote($table) . ' ADD UNIQUE (' . $unique . ')') or mysql_die();
        }
    }
    // end if
    // Go back to table properties
    $message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenAltered;
    include './tbl_properties.php';
    exit;
} else {
    $action = 'tbl_addfield.php';
    include './tbl_properties.inc.php';
    // Diplays the footer
    echo "\n";
    include './footer.inc.php';
}
Exemplo n.º 17
0
    echo show_docu('manual_Reference.html#OPTIMIZE_TABLE') . "\n";
    ?>
    </li>
    <?php 
    echo "\n";
}
// end MySQL < 3.23
?>

    <!-- Deletes the table -->
    <li>
        <a href="sql.php?<?php 
echo ereg_replace('tbl_properties.php$', 'db_details.php', $url_query);
?>
&back=tbl_properties.php&reload=true&sql_query=<?php 
echo urlencode('DROP TABLE ' . backquote($table));
?>
&zero_rows=<?php 
echo urlencode($strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenDropped);
?>
">
            <?php 
echo $strDropTable . ' ' . htmlspecialchars($table);
?>
</a> 
    </li> 

</ul>

<?php 
/**
Exemplo n.º 18
0
    ?>
&nbsp;</td>
</tr>
    <?php 
}
// end while
echo "\n";
?>
</table>


<?php 
/**
 * Displays indexes
 */
$local_query = 'SHOW KEYS FROM ' . backquote($table);
$result = mysql_query($local_query) or mysql_die('', $local_query);
if (mysql_num_rows($result) > 0) {
    ?>

<!-- Indexes -->
<br />
<?php 
    echo $strIndexes . '&nbsp;:' . "\n";
    ?>
<table border="<?php 
    echo $cfgBorder;
    ?>
">
<tr>
    <th><?php 
Exemplo n.º 19
0
    <!-- Drop database -->
    <li>
        <a href="sql.php?server=<?php 
    echo $server;
    ?>
&lang=<?php 
    echo $lang;
    ?>
&db=<?php 
    echo urlencode($db);
    ?>
&sql_query=<?php 
    echo urlencode('DROP DATABASE ' . backquote($db));
    ?>
&zero_rows=<?php 
    echo urlencode($strDatabase . ' ' . htmlspecialchars(backquote($db)) . ' ' . $strHasBeenDropped);
    ?>
&goto=main.php&back=db_details.php&reload=true">
            <?php 
    echo $strDropDB . ' ' . htmlspecialchars($db);
    ?>
</a>
        <?php 
    echo show_docu('manual_Reference.html#DROP_DATABASE') . "\n";
    ?>
    </li>
    <?php 
}
echo "\n";
?>
Exemplo n.º 20
0
    }
    for ($i = 0; $i < count($field_unique); $i++) {
        $j = $field_unique[$i];
        if (!empty($field_name[$j])) {
            $unique .= backquote($field_name[$j]) . ', ';
        }
    }
    // end for
    $unique = ereg_replace(', $', '', $unique);
    if (!empty($unique)) {
        $unique = ', UNIQUE (' . $unique . ')';
    }
    $query_keys = $primary . $index . $unique;
    $query_keys = ereg_replace(', $', '', $query_keys);
    // Builds the 'create table' statement
    $sql_query = 'CREATE TABLE ' . backquote($table) . ' (' . $query . ' ' . $query_keys . ')';
    // Adds table type (2 May 2001 - Robbat2)
    if (!empty($tbl_type) && $tbl_type != 'Default') {
        $sql_query .= ' TYPE = ' . $tbl_type;
    }
    if (MYSQL_INT_VERSION >= 32300 && !empty($comment)) {
        $sql_query .= ' comment = \'' . sql_addslashes($comment) . '\'';
    }
    // Executes the query
    $result = mysql_query($sql_query) or mysql_die();
    $message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenCreated;
    include './tbl_properties.php';
    exit;
} else {
    if (isset($num_fields)) {
        $num_fields = intval($num_fields);
Exemplo n.º 21
0
        // end switch
        if (empty($funcs[$encoded_key])) {
            $valuelist .= $val . ', ';
        } else {
            if ($val == '\'\'' && ereg('^(NOW|CURDATE|CURTIME|UNIX_TIMESTAMP|RAND|USER|LAST_INSERT_ID)$', $funcs[$encoded_key])) {
                $valuelist .= $funcs[$encoded_key] . '(), ';
            } else {
                $valuelist .= $funcs[$encoded_key] . "({$val}), ";
            }
        }
    }
    // end while
    // Builds the sql insert query
    $fieldlist = ereg_replace(', $', '', $fieldlist);
    $valuelist = ereg_replace(', $', '', $valuelist);
    $query = 'INSERT INTO ' . backquote($table) . ' (' . $fieldlist . ') VALUES (' . $valuelist . ')';
    $message = $strInsertedRows . '&nbsp;';
}
// end row insertion
/**
 * Executes the sql query and get the result, then move back to the calling
 * page
 */
mysql_select_db($db);
$sql_query = $query;
$result = mysql_query($query);
if (!$result) {
    $error = mysql_error();
    include './header.inc.php';
    mysql_die($error);
} else {
Exemplo n.º 22
0
    </div>
    <div id="el2Child" class="child" style="margin-bottom: 5px">
    <?php 
        // Displays the list of tables from the current database
        for ($j = 0; $j < $num_tables; $j++) {
            $table = mysql_tablename($tables, $j);
            echo "\n";
            ?>
        <nobr><a target="phpmain" href="sql.php?<?php 
            echo $common_url_query;
            ?>
&table=<?php 
            echo urlencode($table);
            ?>
&sql_query=<?php 
            echo urlencode('SELECT * FROM ' . backquote($table));
            ?>
&pos=0&goto=tbl_properties.php">
                  <img src="browse.gif" border="0" alt="<?php 
            echo "{$strBrowse}: {$table}";
            ?>
" /></a>&nbsp;
              <a class="tblItem" target="phpmain" href="tbl_properties.php?<?php 
            echo $common_url_query;
            ?>
&table=<?php 
            echo urlencode($table);
            ?>
">
                  <?php 
            echo $table;