function PMA_transformation_text_plain__sql($buffer, $options = array(), $meta = '')
{
    $result = PMA_SQP_formatHtml(PMA_SQP_parse($buffer));
    // Need to clear error state not to break subsequent queries display.
    PMA_SQP_resetError();
    return $result;
}
示例#2
0
 public static function html($_sql, $removeNewLines = false)
 {
     global $settings;
     if (!$settings['sqlColor']) {
         return $_sql;
     }
     try {
         $_sql = PMA_SQP_formatHtml(self::parsePMA($_sql));
         if ($removeNewLines) {
             $sql = str_replace(array('<br>', '<br/>', '<br />'), ' ', $_sql);
             $sql = str_replace('<div', ' <span', $_sql);
         }
         return $_sql;
     } catch (exception $e) {
         return $_sql;
     }
 }
示例#3
0
function executeQuery($queryOrQueryAndParams)
{
    global $trackDbSpeed, $traceSqlQueries, $sqlQueryDump, $dbPrefix, $dbClasses;
    if (is_array($queryOrQueryAndParams)) {
        $query = array_shift($queryOrQueryAndParams);
        $args = $queryOrQueryAndParams;
    } else {
        $query = $queryOrQueryAndParams;
        $args = func_get_args();
        if (count($args) > 1) {
            array_shift($args);
        } else {
            $args = array();
        }
    }
    $query = preg_replace("/@(" . implode("|", $dbClasses) . ")/", "{$dbPrefix}\$1", $query);
    if (count($args)) {
        $query = preg_replace(array("/'%/", "/%'/"), array("'%%", "%%'"), $query);
        $query = preg_replace(array("/#[^#]+#/", "/`[^`]+`/"), array("'%s'", "`%s`"), $query);
        $query = vsprintf($query, array_map("quoteSQL", $args));
    }
    if (isset($trackDbSpeed) && $trackDbSpeed) {
        $result = speedTrackExecuteQuery($query);
    } else {
        $result = mysql_query($query);
    }
    if ($result == 0) {
        handleErrorSql($query);
    }
    if ($traceSqlQueries) {
        require_once GORUM_DIR . "/sqlparser.php";
        $parsed_sql = PMA_SQP_parse($query);
        $sqlQueryDump .= PMA_SQP_formatHtml($parsed_sql);
        $sqlQueryDump .= "<br><br>";
    }
    return $result;
}
示例#4
0
 /**
  * Copies or renames table
  *
  * @param string $source_db    source database
  * @param string $source_table source table
  * @param string $target_db    target database
  * @param string $target_table target table
  * @param string $what         what to be moved or copied (data, dataonly)
  * @param bool   $move         whether to move
  * @param string $mode         mode
  *
  * @return bool true if success, false otherwise
  */
 public static function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $move, $mode)
 {
     global $err_url;
     /* Try moving table directly */
     if ($move && $what == 'data') {
         $tbl = new PMA_Table($source_table, $source_db);
         $result = $tbl->rename($target_table, $target_db);
         if ($result) {
             $GLOBALS['message'] = $tbl->getLastMessage();
             return true;
         }
     }
     // set export settings we need
     $GLOBALS['sql_backquotes'] = 1;
     $GLOBALS['asfile'] = 1;
     // Ensure the target is valid
     if (!$GLOBALS['pma']->databases->exists($source_db, $target_db)) {
         if (!$GLOBALS['pma']->databases->exists($source_db)) {
             $GLOBALS['message'] = PMA_Message::rawError(sprintf(__('Source database `%s` was not found!'), htmlspecialchars($source_db)));
         }
         if (!$GLOBALS['pma']->databases->exists($target_db)) {
             $GLOBALS['message'] = PMA_Message::rawError(sprintf(__('Target database `%s` was not found!'), htmlspecialchars($target_db)));
         }
         return false;
     }
     $source = PMA_Util::backquote($source_db) . '.' . PMA_Util::backquote($source_table);
     if (!isset($target_db) || !strlen($target_db)) {
         $target_db = $source_db;
     }
     // Doing a select_db could avoid some problems with replicated databases,
     // when moving table from replicated one to not replicated one
     PMA_DBI_select_db($target_db);
     $target = PMA_Util::backquote($target_db) . '.' . PMA_Util::backquote($target_table);
     // do not create the table if dataonly
     if ($what != 'dataonly') {
         include_once "libraries/plugin_interface.lib.php";
         // get Export SQL instance
         $export_sql_plugin = PMA_getPlugin("export", "sql", 'libraries/plugins/export/', array('export_type' => 'table', 'single_table' => isset($single_table)));
         $no_constraints_comments = true;
         $GLOBALS['sql_constraints_query'] = '';
         $sql_structure = $export_sql_plugin->getTableDef($source_db, $source_table, "\n", $err_url, false, false);
         unset($no_constraints_comments);
         $parsed_sql = PMA_SQP_parse($sql_structure);
         $analyzed_sql = PMA_SQP_analyze($parsed_sql);
         $i = 0;
         if (empty($analyzed_sql[0]['create_table_fields'])) {
             // this is not a CREATE TABLE, so find the first VIEW
             $target_for_view = PMA_Util::backquote($target_db);
             while (true) {
                 if ($parsed_sql[$i]['type'] == 'alpha_reservedWord' && $parsed_sql[$i]['data'] == 'VIEW') {
                     break;
                 }
                 $i++;
             }
         }
         unset($analyzed_sql);
         if (PMA_DRIZZLE) {
             $table_delimiter = 'quote_backtick';
         } else {
             $server_sql_mode = PMA_DBI_fetch_value("SHOW VARIABLES LIKE 'sql_mode'", 0, 1);
             // ANSI_QUOTES might be a subset of sql_mode, for example
             // REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ANSI
             if (false !== strpos($server_sql_mode, 'ANSI_QUOTES')) {
                 $table_delimiter = 'quote_double';
             } else {
                 $table_delimiter = 'quote_backtick';
             }
             unset($server_sql_mode);
         }
         /* Find table name in query and replace it */
         while ($parsed_sql[$i]['type'] != $table_delimiter) {
             $i++;
         }
         /* no need to backquote() */
         if (isset($target_for_view)) {
             // this a view definition; we just found the first db name
             // that follows DEFINER VIEW
             // so change it for the new db name
             $parsed_sql[$i]['data'] = $target_for_view;
             // then we have to find all references to the source db
             // and change them to the target db, ensuring we stay into
             // the $parsed_sql limits
             $last = $parsed_sql['len'] - 1;
             $backquoted_source_db = PMA_Util::backquote($source_db);
             for (++$i; $i <= $last; $i++) {
                 if ($parsed_sql[$i]['type'] == $table_delimiter && $parsed_sql[$i]['data'] == $backquoted_source_db && $parsed_sql[$i - 1]['type'] != 'punct_qualifier') {
                     $parsed_sql[$i]['data'] = $target_for_view;
                 }
             }
             unset($last, $backquoted_source_db);
         } else {
             $parsed_sql[$i]['data'] = $target;
         }
         /* Generate query back */
         $sql_structure = PMA_SQP_formatHtml($parsed_sql, 'query_only');
         // If table exists, and 'add drop table' is selected: Drop it!
         $drop_query = '';
         if (isset($_REQUEST['drop_if_exists']) && $_REQUEST['drop_if_exists'] == 'true') {
             if (PMA_Table::isView($target_db, $target_table)) {
                 $drop_query = 'DROP VIEW';
             } else {
                 $drop_query = 'DROP TABLE';
             }
             $drop_query .= ' IF EXISTS ' . PMA_Util::backquote($target_db) . '.' . PMA_Util::backquote($target_table);
             PMA_DBI_query($drop_query);
             $GLOBALS['sql_query'] .= "\n" . $drop_query . ';';
             // If an existing table gets deleted, maintain any
             // entries for the PMA_* tables
             $maintain_relations = true;
         }
         @PMA_DBI_query($sql_structure);
         $GLOBALS['sql_query'] .= "\n" . $sql_structure . ';';
         if (($move || isset($GLOBALS['add_constraints'])) && !empty($GLOBALS['sql_constraints_query'])) {
             $parsed_sql = PMA_SQP_parse($GLOBALS['sql_constraints_query']);
             $i = 0;
             // find the first $table_delimiter, it must be the source
             // table name
             while ($parsed_sql[$i]['type'] != $table_delimiter) {
                 $i++;
                 // maybe someday we should guard against going over limit
                 //if ($i == $parsed_sql['len']) {
                 //    break;
                 //}
             }
             // replace it by the target table name, no need
             // to backquote()
             $parsed_sql[$i]['data'] = $target;
             // now we must remove all $table_delimiter that follow a
             // CONSTRAINT keyword, because a constraint name must be
             // unique in a db
             $cnt = $parsed_sql['len'] - 1;
             for ($j = $i; $j < $cnt; $j++) {
                 if ($parsed_sql[$j]['type'] == 'alpha_reservedWord' && strtoupper($parsed_sql[$j]['data']) == 'CONSTRAINT') {
                     if ($parsed_sql[$j + 1]['type'] == $table_delimiter) {
                         $parsed_sql[$j + 1]['data'] = '';
                     }
                 }
             }
             // Generate query back
             $GLOBALS['sql_constraints_query'] = PMA_SQP_formatHtml($parsed_sql, 'query_only');
             if ($mode == 'one_table') {
                 PMA_DBI_query($GLOBALS['sql_constraints_query']);
             }
             $GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_constraints_query'];
             if ($mode == 'one_table') {
                 unset($GLOBALS['sql_constraints_query']);
             }
         }
     } else {
         $GLOBALS['sql_query'] = '';
     }
     // Copy the data unless this is a VIEW
     if (($what == 'data' || $what == 'dataonly') && !PMA_Table::isView($target_db, $target_table)) {
         $sql_set_mode = "SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO'";
         PMA_DBI_query($sql_set_mode);
         $GLOBALS['sql_query'] .= "\n\n" . $sql_set_mode . ';';
         $sql_insert_data = 'INSERT INTO ' . $target . ' SELECT * FROM ' . $source;
         PMA_DBI_query($sql_insert_data);
         $GLOBALS['sql_query'] .= "\n\n" . $sql_insert_data . ';';
     }
     $GLOBALS['cfgRelation'] = PMA_getRelationsParam();
     // Drops old table if the user has requested to move it
     if ($move) {
         // This could avoid some problems with replicated databases, when
         // moving table from replicated one to not replicated one
         PMA_DBI_select_db($source_db);
         if (PMA_Table::isView($source_db, $source_table)) {
             $sql_drop_query = 'DROP VIEW';
         } else {
             $sql_drop_query = 'DROP TABLE';
         }
         $sql_drop_query .= ' ' . $source;
         PMA_DBI_query($sql_drop_query);
         // Renable table in configuration storage
         PMA_REL_renameTable($source_db, $target_db, $source_table, $target_table);
         $GLOBALS['sql_query'] .= "\n\n" . $sql_drop_query . ';';
         // end if ($move)
     } else {
         // we are copying
         // Create new entries as duplicates from old PMA DBs
         if ($what != 'dataonly' && !isset($maintain_relations)) {
             if ($GLOBALS['cfgRelation']['commwork']) {
                 // Get all comments and MIME-Types for current table
                 $comments_copy_query = 'SELECT
                                             column_name, comment' . ($GLOBALS['cfgRelation']['mimework'] ? ', mimetype, transformation, transformation_options' : '') . '
                                         FROM ' . PMA_Util::backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_Util::backquote($GLOBALS['cfgRelation']['column_info']) . '
                                         WHERE
                                             db_name = \'' . PMA_Util::sqlAddSlashes($source_db) . '\' AND
                                             table_name = \'' . PMA_Util::sqlAddSlashes($source_table) . '\'';
                 $comments_copy_rs = PMA_queryAsControlUser($comments_copy_query);
                 // Write every comment as new copied entry. [MIME]
                 while ($comments_copy_row = PMA_DBI_fetch_assoc($comments_copy_rs)) {
                     $new_comment_query = 'REPLACE INTO ' . PMA_Util::backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_Util::backquote($GLOBALS['cfgRelation']['column_info']) . ' (db_name, table_name, column_name, comment' . ($GLOBALS['cfgRelation']['mimework'] ? ', mimetype, transformation, transformation_options' : '') . ') ' . ' VALUES(' . '\'' . PMA_Util::sqlAddSlashes($target_db) . '\',' . '\'' . PMA_Util::sqlAddSlashes($target_table) . '\',' . '\'' . PMA_Util::sqlAddSlashes($comments_copy_row['column_name']) . '\'' . ($GLOBALS['cfgRelation']['mimework'] ? ',\'' . PMA_Util::sqlAddSlashes($comments_copy_row['comment']) . '\',' . '\'' . PMA_Util::sqlAddSlashes($comments_copy_row['mimetype']) . '\',' . '\'' . PMA_Util::sqlAddSlashes($comments_copy_row['transformation']) . '\',' . '\'' . PMA_Util::sqlAddSlashes($comments_copy_row['transformation_options']) . '\'' : '') . ')';
                     PMA_queryAsControlUser($new_comment_query);
                 }
                 // end while
                 PMA_DBI_free_result($comments_copy_rs);
                 unset($comments_copy_rs);
             }
             // duplicating the bookmarks must not be done here, but
             // just once per db
             $get_fields = array('display_field');
             $where_fields = array('db_name' => $source_db, 'table_name' => $source_table);
             $new_fields = array('db_name' => $target_db, 'table_name' => $target_table);
             PMA_Table::duplicateInfo('displaywork', 'table_info', $get_fields, $where_fields, $new_fields);
             /**
              * @todo revise this code when we support cross-db relations
              */
             $get_fields = array('master_field', 'foreign_table', 'foreign_field');
             $where_fields = array('master_db' => $source_db, 'master_table' => $source_table);
             $new_fields = array('master_db' => $target_db, 'foreign_db' => $target_db, 'master_table' => $target_table);
             PMA_Table::duplicateInfo('relwork', 'relation', $get_fields, $where_fields, $new_fields);
             $get_fields = array('foreign_field', 'master_table', 'master_field');
             $where_fields = array('foreign_db' => $source_db, 'foreign_table' => $source_table);
             $new_fields = array('master_db' => $target_db, 'foreign_db' => $target_db, 'foreign_table' => $target_table);
             PMA_Table::duplicateInfo('relwork', 'relation', $get_fields, $where_fields, $new_fields);
             $get_fields = array('x', 'y', 'v', 'h');
             $where_fields = array('db_name' => $source_db, 'table_name' => $source_table);
             $new_fields = array('db_name' => $target_db, 'table_name' => $target_table);
             PMA_Table::duplicateInfo('designerwork', 'designer_coords', $get_fields, $where_fields, $new_fields);
             /**
             * @todo Can't get duplicating PDFs the right way. The
             * page numbers always get screwed up independently from
             * duplication because the numbers do not seem to be stored on a
             * per-database basis. Would the author of pdf support please
             * have a look at it?
             *
                             $get_fields = array('page_descr');
                             $where_fields = array('db_name' => $source_db);
                             $new_fields = array('db_name' => $target_db);
                             $last_id = PMA_Table::duplicateInfo(
                'pdfwork',
                'pdf_pages',
                $get_fields,
                $where_fields,
                $new_fields
                             );
             
                             if (isset($last_id) && $last_id >= 0) {
                $get_fields = array('x', 'y');
                $where_fields = array(
                    'db_name' => $source_db,
                    'table_name' => $source_table
                );
                $new_fields = array(
                    'db_name' => $target_db,
                    'table_name' => $target_table,
                    'pdf_page_number' => $last_id
                );
                PMA_Table::duplicateInfo(
                    'pdfwork',
                    'table_coords',
                    $get_fields,
                    $where_fields,
                    $new_fields
                );
                             }
             */
         }
     }
     return true;
 }
示例#5
0
            $unlim_num_rows = PMA_Table::countRecords($db, $table);

        } else { // n o t   " j u s t   b r o w s i n g "

            // add select expression after the SQL_CALC_FOUND_ROWS

            // for UNION, just adding SQL_CALC_FOUND_ROWS
            // after the first SELECT works.

            // take the left part, could be:
            // SELECT
            // (SELECT
            $count_query = PMA_SQP_formatHtml($parsed_sql, 'query_only', 0, $analyzed_sql[0]['position_of_first_select'] + 1);
            $count_query .= ' SQL_CALC_FOUND_ROWS ';
            // add everything that was after the first SELECT
            $count_query .= PMA_SQP_formatHtml($parsed_sql, 'query_only', $analyzed_sql[0]['position_of_first_select'] + 1);
            // ensure there is no semicolon at the end of the
            // count query because we'll probably add
            // a LIMIT 1 clause after it
            $count_query = rtrim($count_query);
            $count_query = rtrim($count_query, ';');

            // if using SQL_CALC_FOUND_ROWS, add a LIMIT to avoid
            // long delays. Returned count will be complete anyway.
            // (but a LIMIT would disrupt results in an UNION)

            if (! isset($analyzed_sql[0]['queryflags']['union'])) {
                $count_query .= ' LIMIT 1';
            }

            // run the count query
示例#6
0
/**
 * Prints server traffic information
 *
 * @param Object $ServerStatusData An instance of the PMA_ServerStatusData class
 *
 * @return string
 */
function getServerTrafficHtml($ServerStatusData)
{
    $hour_factor = 3600 / $ServerStatusData->status['Uptime'];
    $start_time = PMA_DBI_fetch_value('SELECT UNIX_TIMESTAMP() - ' . $ServerStatusData->status['Uptime']);
    $retval = '<h3>';
    $retval .= sprintf(__('Network traffic since startup: %s'), implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_received'] + $ServerStatusData->status['Bytes_sent'], 3, 1)));
    $retval .= '</h3>';
    $retval .= '<p>';
    $retval .= sprintf(__('This MySQL server has been running for %1$s. It started up on %2$s.'), PMA_Util::timespanFormat($ServerStatusData->status['Uptime']), PMA_Util::localisedDate($start_time)) . "\n";
    $retval .= '</p>';
    if ($GLOBALS['server_master_status'] || $GLOBALS['server_slave_status']) {
        $retval .= '<p class="notice">';
        if ($GLOBALS['server_master_status'] && $GLOBALS['server_slave_status']) {
            $retval .= __('This MySQL server works as <b>master</b> and ' . '<b>slave</b> in <b>replication</b> process.');
        } elseif ($GLOBALS['server_master_status']) {
            $retval .= __('This MySQL server works as <b>master</b> ' . 'in <b>replication</b> process.');
        } elseif ($GLOBALS['server_slave_status']) {
            $retval .= __('This MySQL server works as <b>slave</b> ' . 'in <b>replication</b> process.');
        }
        $retval .= ' ';
        $retval .= __('For further information about replication status on the server, ' . 'please visit the <a href="#replication">replication section</a>.');
        $retval .= '</p>';
    }
    /*
     * if the server works as master or slave in replication process,
     * display useful information
     */
    if ($GLOBALS['server_master_status'] || $GLOBALS['server_slave_status']) {
        $retval .= '<hr class="clearfloat" />';
        $retval .= '<h3><a name="replication">';
        $retval .= __('Replication status');
        $retval .= '</a></h3>';
        foreach ($GLOBALS['replication_types'] as $type) {
            if (isset(${"server_{$type}_status"}) && ${"server_{$type}_status"}) {
                PMA_replication_print_status_table($type);
            }
        }
    }
    $retval .= '<table id="serverstatustraffic" class="data noclick">';
    $retval .= '<thead>';
    $retval .= '<tr>';
    $retval .= '<th colspan="2">';
    $retval .= __('Traffic') . '&nbsp;';
    $retval .= PMA_Util::showHint(__('On a busy server, the byte counters may overrun, so those statistics ' . 'as reported by the MySQL server may be incorrect.'));
    $retval .= '</th>';
    $retval .= '<th>&oslash; ' . __('per hour') . '</th>';
    $retval .= '</tr>';
    $retval .= '</thead>';
    $retval .= '<tbody>';
    $retval .= '<tr class="odd">';
    $retval .= '<th class="name">' . __('Received') . '</th>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_received'], 3, 1));
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_received'] * $hour_factor, 3, 1));
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr class="even">';
    $retval .= '<th class="name">' . __('Sent') . '</th>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_sent'], 3, 1));
    $retval .= '</td>';
    $retval .= '<td class="value"><?php echo';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_sent'] * $hour_factor, 3, 1));
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr class="odd">';
    $retval .= '<th class="name">' . __('Total') . '</th>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown($ServerStatusData->status['Bytes_received'] + $ServerStatusData->status['Bytes_sent'], 3, 1));
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= implode(' ', PMA_Util::formatByteDown(($ServerStatusData->status['Bytes_received'] + $ServerStatusData->status['Bytes_sent']) * $hour_factor, 3, 1));
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '</tbody>';
    $retval .= '</table>';
    $retval .= '<table id="serverstatusconnections" class="data noclick">';
    $retval .= '<thead>';
    $retval .= '<tr>';
    $retval .= '<th colspan="2">' . __('Connections') . '</th>';
    $retval .= '<th>&oslash; ' . __('per hour') . '</th>';
    $retval .= '<th>%</th>';
    $retval .= '</tr>';
    $retval .= '</thead>';
    $retval .= '<tbody>';
    $retval .= '<tr class="odd">';
    $retval .= '<th class="name">' . __('max. concurrent connections') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Max_used_connections'], 0);
    $retval .= '</td>';
    $retval .= '<td class="value">--- </td>';
    $retval .= '<td class="value">--- </td>';
    $retval .= '</tr>';
    $retval .= '<tr class="even">';
    $retval .= '<th class="name">' . __('Failed attempts') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_connects'], 4, 1, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_connects'] * $hour_factor, 4, 2, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    if ($ServerStatusData->status['Connections'] > 0) {
        $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_connects'] * 100 / $ServerStatusData->status['Connections'], 0, 2, true);
        $retval .= '%';
    } else {
        $retval .= '--- ';
    }
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr class="odd">';
    $retval .= '<th class="name">' . __('Aborted') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_clients'], 4, 1, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_clients'] * $hour_factor, 4, 2, true);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    if ($ServerStatusData->status['Connections'] > 0) {
        $retval .= PMA_Util::formatNumber($ServerStatusData->status['Aborted_clients'] * 100 / $ServerStatusData->status['Connections'], 0, 2, true);
        $retval .= '%';
    } else {
        $retval .= '--- ';
    }
    $retval .= '</td>';
    $retval .= '</tr>';
    $retval .= '<tr class="even">';
    $retval .= '<th class="name">' . __('Total') . '</th>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Connections'], 4, 0);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber($ServerStatusData->status['Connections'] * $hour_factor, 4, 2);
    $retval .= '</td>';
    $retval .= '<td class="value">';
    $retval .= PMA_Util::formatNumber(100, 0, 2);
    $retval .= '%</td>';
    $retval .= '</tr>';
    $retval .= '</tbody>';
    $retval .= '</table>';
    $url_params = array();
    $show_full_sql = !empty($_REQUEST['full']);
    if ($show_full_sql) {
        $url_params['full'] = 1;
        $full_text_link = 'server_status.php' . PMA_generate_common_url(array(), 'html', '?');
    } else {
        $full_text_link = 'server_status.php' . PMA_generate_common_url(array('full' => 1));
    }
    // This array contains display name and real column name of each
    // sortable column in the table
    $sortable_columns = array(array('column_name' => __('ID'), 'order_by_field' => 'Id'), array('column_name' => __('User'), 'order_by_field' => 'User'), array('column_name' => __('Host'), 'order_by_field' => 'Host'), array('column_name' => __('Database'), 'order_by_field' => 'db'), array('column_name' => __('Command'), 'order_by_field' => 'Command'), array('column_name' => __('Time'), 'order_by_field' => 'Time'), array('column_name' => __('Status'), 'order_by_field' => 'State'), array('column_name' => __('SQL query'), 'order_by_field' => 'Info'));
    $sortable_columns_count = count($sortable_columns);
    if (PMA_DRIZZLE) {
        $sql_query = "SELECT\n                p.id       AS Id,\n                p.username AS User,\n                p.host     AS Host,\n                p.db       AS db,\n                p.command  AS Command,\n                p.time     AS Time,\n                p.state    AS State,\n                " . ($show_full_sql ? 's.query' : 'left(p.info, ' . (int) $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] . ')') . " AS Info\n            FROM data_dictionary.PROCESSLIST p\n                " . ($show_full_sql ? 'LEFT JOIN data_dictionary.SESSIONS s ON s.session_id = p.id' : '');
        if (!empty($_REQUEST['order_by_field']) && !empty($_REQUEST['sort_order'])) {
            $sql_query .= ' ORDER BY p.' . $_REQUEST['order_by_field'] . ' ' . $_REQUEST['sort_order'];
        }
    } else {
        $sql_query = $show_full_sql ? 'SHOW FULL PROCESSLIST' : 'SHOW PROCESSLIST';
        if (!empty($_REQUEST['order_by_field']) && !empty($_REQUEST['sort_order'])) {
            $sql_query = 'SELECT * FROM `INFORMATION_SCHEMA`.`PROCESSLIST` ORDER BY `' . $_REQUEST['order_by_field'] . '` ' . $_REQUEST['sort_order'];
        }
    }
    $result = PMA_DBI_query($sql_query);
    /**
     * Displays the page
     */
    $retval .= '<table id="tableprocesslist" class="data clearfloat noclick sortable">';
    $retval .= '<thead>';
    $retval .= '<tr>';
    $retval .= '<th>' . __('Processes') . '</th>';
    foreach ($sortable_columns as $column) {
        $is_sorted = !empty($_REQUEST['order_by_field']) && !empty($_REQUEST['sort_order']) && $_REQUEST['order_by_field'] == $column['order_by_field'];
        $column['sort_order'] = 'ASC';
        if ($is_sorted && $_REQUEST['sort_order'] === 'ASC') {
            $column['sort_order'] = 'DESC';
        }
        if ($is_sorted) {
            if ($_REQUEST['sort_order'] == 'ASC') {
                $asc_display_style = 'inline';
                $desc_display_style = 'none';
            } elseif ($_REQUEST['sort_order'] == 'DESC') {
                $desc_display_style = 'inline';
                $asc_display_style = 'none';
            }
        }
        $retval .= '<th>';
        $retval .= '<a href="server_status.php' . PMA_generate_common_url($column) . '" ';
        if ($is_sorted) {
            $retval .= 'onmouseout="$(\'.soimg\').toggle()" ' . 'onmouseover="$(\'.soimg\').toggle()"';
        }
        $retval .= '>';
        $retval .= $column['column_name'];
        if ($is_sorted) {
            $retval .= '<img class="icon ic_s_desc soimg" alt="' . __('Descending') . '" title="" src="themes/dot.gif" ' . 'style="display: ' . $desc_display_style . '" />';
            $retval .= '<img class="icon ic_s_asc soimg hide" alt="' . __('Ascending') . '" title="" src="themes/dot.gif" ' . 'style="display: ' . $asc_display_style . '" />';
        }
        $retval .= '</a>';
        if (!PMA_DRIZZLE && 0 === --$sortable_columns_count) {
            $retval .= '<a href="' . $full_text_link . '">';
            if ($show_full_sql) {
                $retval .= PMA_Util::getImage('s_partialtext.png', __('Truncate Shown Queries'));
            } else {
                $retval .= PMA_Util::getImage('s_fulltext.png', __('Show Full Queries'));
            }
            $retval .= '</a>';
        }
        $retval .= '</th>';
    }
    $retval .= '</tr>';
    $retval .= '</thead>';
    $retval .= '<tbody>';
    $odd_row = true;
    while ($process = PMA_DBI_fetch_assoc($result)) {
        // Array keys need to modify due to the way it has used
        // to display column values
        if (!empty($_REQUEST['order_by_field']) && !empty($_REQUEST['sort_order'])) {
            foreach (array_keys($process) as $key) {
                $new_key = ucfirst(strtolower($key));
                $process[$new_key] = $process[$key];
                unset($process[$key]);
            }
        }
        $url_params['kill'] = $process['Id'];
        $kill_process = 'server_status.php' . PMA_generate_common_url($url_params);
        $retval .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">';
        $retval .= '<td><a href="' . $kill_process . '">' . __('Kill') . '</a></td>';
        $retval .= '<td class="value">' . $process['Id'] . '</td>';
        $retval .= '<td>' . htmlspecialchars($process['User']) . '</td>';
        $retval .= '<td>' . htmlspecialchars($process['Host']) . '</td>';
        $retval .= '<td>' . (!isset($process['db']) || !strlen($process['db']) ? '<i>' . __('None') . '</i>' : htmlspecialchars($process['db'])) . '</td>';
        $retval .= '<td>' . htmlspecialchars($process['Command']) . '</td>';
        $retval .= '<td class="value">' . $process['Time'] . '</td>';
        $retval .= '<td>' . (empty($process['State']) ? '---' : $process['State']) . '</td>';
        $retval .= '<td>';
        if (empty($process['Info'])) {
            $retval .= '---';
        } else {
            if (!$show_full_sql && strlen($process['Info']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
                $retval .= htmlspecialchars(substr($process['Info'], 0, $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'])) . '[...]';
            } else {
                $retval .= PMA_SQP_formatHtml(PMA_SQP_parse($process['Info']));
            }
        }
        $retval .= '</td>';
        $retval .= '</tr>';
        $odd_row = !$odd_row;
    }
    $retval .= '</tbody>';
    $retval .= '</table>';
    return $retval;
}
    echo !isset($process['db']) || !strlen($process['db']) ? '<i>' . $strNone . '</i>' : $process['db'];
    ?>
</td>
    <td><?php 
    echo $process['Command'];
    ?>
</td>
    <td class="value"><?php 
    echo $process['Time'];
    ?>
</td>
    <td><?php 
    echo empty($process['State']) ? '---' : $process['State'];
    ?>
</td>
    <td><?php 
    echo empty($process['Info']) ? '---' : PMA_SQP_formatHtml(PMA_SQP_parse($process['Info']));
    ?>
</td>
</tr>
    <?php 
    $odd_row = !$odd_row;
}
?>
</tbody>
</table>
<?php 
/**
 * Sends the footer
 */
require_once './libraries/footer.inc.php';
示例#8
0
 /**
  * format sql strings
  *
  * @param   mixed    pre-parsed SQL structure
  *
  * @return  string   the formatted sql
  *
  * @global  array    the configuration array
  * @global  boolean  whether the current statement is a multiple one or not
  *
  * @access  public
  *
  * @author  Robin Johnson <*****@*****.**>
  */
 function PMA_formatSql($parsed_sql, $unparsed_sql = '')
 {
     global $cfg;
     // Check that we actually have a valid set of parsed data
     // well, not quite
     // first check for the SQL parser having hit an error
     if (PMA_SQP_isError()) {
         return $parsed_sql;
     }
     // then check for an array
     if (!is_array($parsed_sql)) {
         // We don't so just return the input directly
         // This is intended to be used for when the SQL Parser is turned off
         $formatted_sql = '<pre>' . "\n" . ($cfg['SQP']['fmtType'] == 'none' && $unparsed_sql != '' ? $unparsed_sql : $parsed_sql) . "\n" . '</pre>';
         return $formatted_sql;
     }
     $formatted_sql = '';
     switch ($cfg['SQP']['fmtType']) {
         case 'none':
             if ($unparsed_sql != '') {
                 $formatted_sql = "<pre>\n" . PMA_SQP_formatNone(array('raw' => $unparsed_sql)) . "\n</pre>";
             } else {
                 $formatted_sql = PMA_SQP_formatNone($parsed_sql);
             }
             break;
         case 'html':
             $formatted_sql = PMA_SQP_formatHtml($parsed_sql, 'color');
             break;
         case 'text':
             //$formatted_sql = PMA_SQP_formatText($parsed_sql);
             $formatted_sql = PMA_SQP_formatHtml($parsed_sql, 'text');
             break;
         default:
             break;
     }
     // end switch
     return $formatted_sql;
 }
示例#9
0
    /**
     * format sql strings
     *
     * @param mixed  $parsed_sql   pre-parsed SQL structure
     * @param string $unparsed_sql raw SQL string
     *
     * @return string  the formatted sql
     *
     * @global  array    the configuration array
     * @global  boolean  whether the current statement is a multiple one or not
     *
     * @access  public
     * @todo    move into PMA_Sql
     */
    public static function formatSql($parsed_sql, $unparsed_sql = '')
    {
        global $cfg;

        // Check that we actually have a valid set of parsed data
        // well, not quite
        // first check for the SQL parser having hit an error
        if (PMA_SQP_isError()) {
            return htmlspecialchars($parsed_sql['raw']);
        }
        // then check for an array
        if (! is_array($parsed_sql)) {
            // We don't so just return the input directly
            // This is intended to be used for when the SQL Parser is turned off
            $formatted_sql = "<pre>\n";
            if (($cfg['SQP']['fmtType'] == 'none') && ($unparsed_sql != '')) {
                $formatted_sql .= $unparsed_sql;
            } else {
                $formatted_sql .= $parsed_sql;
            }
            $formatted_sql .= "\n</pre>";
            return $formatted_sql;
        }

        $formatted_sql = '';

        switch ($cfg['SQP']['fmtType']) {
        case 'none':
            if ($unparsed_sql != '') {
                $formatted_sql = '<span class="inner_sql"><pre>' . "\n"
                    . PMA_SQP_formatNone(array('raw' => $unparsed_sql)) . "\n"
                    . '</pre></span>';
            } else {
                $formatted_sql = PMA_SQP_formatNone($parsed_sql);
            }
            break;
        case 'html':
            $formatted_sql = PMA_SQP_formatHtml($parsed_sql, 'color');
            break;
        case 'text':
            $formatted_sql = PMA_SQP_formatHtml($parsed_sql, 'text');
            break;
        default:
            break;
        } // end switch

        return $formatted_sql;
    } // end of the "formatSql()" function
示例#10
0
function SQLFormatPHP($in)
{
    return PMA_SQP_formatHtml(PMA_SQP_parse($in), 'text');
}
示例#11
0
    echo $useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
    ?>
" align="right">&nbsp;<?php 
    echo $value['Time'];
    ?>
&nbsp;</td>
        <td bgcolor="<?php 
    echo $useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
    ?>
">&nbsp;<?php 
    echo empty($value['State']) ? '---' : $value['State'];
    ?>
&nbsp;</td>
        <td bgcolor="<?php 
    echo $useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo'];
    ?>
">&nbsp;<?php 
    echo empty($value['Info']) ? '---' : PMA_SQP_formatHtml(PMA_SQP_parse($value['Info']));
    ?>
&nbsp;</td>
    </tr>
<?php 
    $useBgcolorOne = !$useBgcolorOne;
}
?>
</table>
<?php 
/**
 * Sends the footer
 */
require_once './footer.inc.php';
示例#12
0
/**
 * Copies or renames table
 * FIXME: use RENAME
 *
 * @author          Michal Čihař <*****@*****.**>
 */
function PMA_table_move_copy($source_db, $source_table, $target_db, $target_table, $what, $move)
{
    global $cfgRelation, $dblist, $err_url, $sql_query;
    // set export settings we need
    $GLOBALS['use_backquotes'] = 1;
    $GLOBALS['asfile'] = 1;
    // Ensure the target is valid
    if (count($dblist) > 0 && (PMA_isInto($source_db, $dblist) == -1 || PMA_isInto($target_db, $dblist) == -1)) {
        exit;
    }
    $source = PMA_backquote($source_db) . '.' . PMA_backquote($source_table);
    if (empty($target_db)) {
        $target_db = $source_db;
    }
    // This could avoid some problems with replicated databases, when
    // moving table from replicated one to not replicated one
    PMA_DBI_select_db($target_db);
    $target = PMA_backquote($target_db) . '.' . PMA_backquote($target_table);
    // do not create the table if dataonly
    if ($what != 'dataonly') {
        require_once './libraries/export/sql.php';
        $no_constraints_comments = true;
        $sql_structure = PMA_getTableDef($source_db, $source_table, "\n", $err_url);
        unset($no_constraints_comments);
        $parsed_sql = PMA_SQP_parse($sql_structure);
        /* nijel: Find table name in query and replace it */
        $i = 0;
        while ($parsed_sql[$i]['type'] != 'quote_backtick') {
            $i++;
        }
        /* no need to PMA_backquote() */
        $parsed_sql[$i]['data'] = $target;
        /* Generate query back */
        $sql_structure = PMA_SQP_formatHtml($parsed_sql, 'query_only');
        // If table exists, and 'add drop table' is selected: Drop it!
        $drop_query = '';
        if (isset($GLOBALS['drop_if_exists']) && $GLOBALS['drop_if_exists'] == 'true') {
            $drop_query = 'DROP TABLE IF EXISTS ' . PMA_backquote($target_db) . '.' . PMA_backquote($target_table);
            $result = PMA_DBI_query($drop_query);
            if (isset($sql_query)) {
                $sql_query .= "\n" . $drop_query . ';';
            } else {
                $sql_query = $drop_query . ';';
            }
            // garvin: If an existing table gets deleted, maintain any entries
            // for the PMA_* tables
            $maintain_relations = TRUE;
        }
        $result = @PMA_DBI_query($sql_structure);
        if (isset($sql_query)) {
            $sql_query .= "\n" . $sql_structure . ';';
        } else {
            $sql_query = $sql_structure . ';';
        }
        if (($move || isset($GLOBALS['constraints'])) && isset($GLOBALS['sql_constraints'])) {
            $parsed_sql = PMA_SQP_parse($GLOBALS['sql_constraints']);
            $i = 0;
            while ($parsed_sql[$i]['type'] != 'quote_backtick') {
                $i++;
            }
            /* no need to PMA_backquote() */
            $parsed_sql[$i]['data'] = $target;
            /* Generate query back */
            $GLOBALS['sql_constraints'] = PMA_SQP_formatHtml($parsed_sql, 'query_only');
            $result = PMA_DBI_query($GLOBALS['sql_constraints']);
            if (isset($sql_query)) {
                $sql_query .= "\n" . $GLOBALS['sql_constraints'];
            } else {
                $sql_query = $GLOBALS['sql_constraints'];
            }
            unset($GLOBALS['sql_constraints']);
        }
    } else {
        $sql_query = '';
    }
    // Copy the data
    //if ($result != FALSE && ($what == 'data' || $what == 'dataonly')) {
    if ($what == 'data' || $what == 'dataonly') {
        $sql_insert_data = 'INSERT INTO ' . $target . ' SELECT * FROM ' . $source;
        PMA_DBI_query($sql_insert_data);
        $sql_query .= "\n\n" . $sql_insert_data . ';';
    }
    require_once './libraries/relation.lib.php';
    $cfgRelation = PMA_getRelationsParam();
    // Drops old table if the user has requested to move it
    if ($move) {
        // This could avoid some problems with replicated databases, when
        // moving table from replicated one to not replicated one
        PMA_DBI_select_db($source_db);
        $sql_drop_table = 'DROP TABLE ' . $source;
        PMA_DBI_query($sql_drop_table);
        // garvin: Move old entries from PMA-DBs to new table
        if ($cfgRelation['commwork']) {
            $remove_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_info']) . ' SET     table_name = \'' . PMA_sqlAddslashes($target_table) . '\', ' . '        db_name    = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
            $rmv_rs = PMA_query_as_cu($remove_query);
            unset($rmv_query);
        }
        // garvin: updating bookmarks is not possible since only a single table is moved,
        // and not the whole DB.
        // if ($cfgRelation['bookmarkwork']) {
        //     $remove_query = 'UPDATE ' . PMA_backquote($cfgRelation['bookmark'])
        //                   . ' SET     dbase = \'' . PMA_sqlAddslashes($target_db) . '\''
        //                   . ' WHERE dbase  = \'' . PMA_sqlAddslashes($source_db) . '\'';
        //     $rmv_rs    = PMA_query_as_cu($remove_query);
        //     unset($rmv_query);
        // }
        if ($cfgRelation['displaywork']) {
            $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_info']) . ' SET     db_name = \'' . PMA_sqlAddslashes($target_db) . '\', ' . '         table_name = \'' . PMA_sqlAddslashes($target_table) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
            $tb_rs = PMA_query_as_cu($table_query);
            unset($table_query);
            unset($tb_rs);
        }
        if ($cfgRelation['relwork']) {
            $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation']) . ' SET     foreign_table = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         foreign_db = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE foreign_db  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND foreign_table = \'' . PMA_sqlAddslashes($source_table) . '\'';
            $tb_rs = PMA_query_as_cu($table_query);
            unset($table_query);
            unset($tb_rs);
            $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['relation']) . ' SET     master_table = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         master_db = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE master_db  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND master_table = \'' . PMA_sqlAddslashes($source_table) . '\'';
            $tb_rs = PMA_query_as_cu($table_query);
            unset($table_query);
            unset($tb_rs);
        }
        // garvin: [TODO] Can't get moving PDFs the right way. The page numbers always
        // get screwed up independently from duplication because the numbers do not
        // seem to be stored on a per-database basis. Would the author of pdf support
        // please have a look at it?
        if ($cfgRelation['pdfwork']) {
            $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['table_coords']) . ' SET     table_name = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
            $tb_rs = PMA_query_as_cu($table_query);
            unset($table_query);
            unset($tb_rs);
            /*
            $pdf_query = 'SELECT pdf_page_number '
                       . ' FROM ' . PMA_backquote($cfgRelation['table_coords'])
                       . ' WHERE db_name  = \'' . PMA_sqlAddslashes($target_db) . '\''
                       . ' AND table_name = \'' . PMA_sqlAddslashes($target_table) . '\'';
            $pdf_rs = PMA_query_as_cu($pdf_query);
            
            while ($pdf_copy_row = PMA_DBI_fetch_assoc($pdf_rs)) {
                $table_query = 'UPDATE ' . PMA_backquote($cfgRelation['pdf_pages'])
                                . ' SET     db_name = \'' . PMA_sqlAddslashes($target_db) . '\''
                                . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\''
                                . ' AND page_nr = \'' . PMA_sqlAddslashes($pdf_copy_row['pdf_page_number']) . '\'';
                $tb_rs    = PMA_query_as_cu($table_query);
                unset($table_query);
                unset($tb_rs);
            }
            */
        }
        $sql_query .= "\n\n" . $sql_drop_table . ';';
    } else {
        // garvin: Create new entries as duplicates from old PMA DBs
        if ($what != 'dataonly' && !isset($maintain_relations)) {
            if ($cfgRelation['commwork']) {
                // Get all comments and MIME-Types for current table
                $comments_copy_query = 'SELECT
                                            column_name, ' . PMA_backquote('comment') . ($cfgRelation['mimework'] ? ', mimetype, transformation, transformation_options' : '') . '
                                        FROM ' . PMA_backquote($cfgRelation['column_info']) . '
                                        WHERE
                                            db_name = \'' . PMA_sqlAddslashes($source_db) . '\' AND
                                            table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
                $comments_copy_rs = PMA_query_as_cu($comments_copy_query);
                // Write every comment as new copied entry. [MIME]
                while ($comments_copy_row = PMA_DBI_fetch_assoc($comments_copy_rs)) {
                    $new_comment_query = 'REPLACE INTO ' . PMA_backquote($cfgRelation['column_info']) . ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ($cfgRelation['mimework'] ? ', mimetype, transformation, transformation_options' : '') . ') ' . ' VALUES(' . '\'' . PMA_sqlAddslashes($target_db) . '\',' . '\'' . PMA_sqlAddslashes($target_table) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['column_name']) . '\'' . ($cfgRelation['mimework'] ? ',\'' . PMA_sqlAddslashes($comments_copy_row['comment']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['mimetype']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['transformation']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['transformation_options']) . '\'' : '') . ')';
                    $new_comment_rs = PMA_query_as_cu($new_comment_query);
                }
                // end while
            }
            if ($source_db != $target_db) {
                $get_fields = array('user', 'label', 'query');
                $where_fields = array('dbase' => $source_db);
                $new_fields = array('dbase' => $target_db);
                PMA_duplicate_table_info('bookmarkwork', 'bookmark', $get_fields, $where_fields, $new_fields);
            }
            $get_fields = array('display_field');
            $where_fields = array('db_name' => $source_db, 'table_name' => $source_table);
            $new_fields = array('db_name' => $target_db, 'table_name' => $target_table);
            PMA_duplicate_table_info('displaywork', 'table_info', $get_fields, $where_fields, $new_fields);
            $get_fields = array('master_field', 'foreign_db', 'foreign_table', 'foreign_field');
            $where_fields = array('master_db' => $source_db, 'master_table' => $source_table);
            $new_fields = array('master_db' => $target_db, 'master_table' => $target_table);
            PMA_duplicate_table_info('relwork', 'relation', $get_fields, $where_fields, $new_fields);
            $get_fields = array('foreign_field', 'master_db', 'master_table', 'master_field');
            $where_fields = array('foreign_db' => $source_db, 'foreign_table' => $source_table);
            $new_fields = array('foreign_db' => $target_db, 'foreign_table' => $target_table);
            PMA_duplicate_table_info('relwork', 'relation', $get_fields, $where_fields, $new_fields);
            // garvin: [TODO] Can't get duplicating PDFs the right way. The page numbers always
            // get screwed up independently from duplication because the numbers do not
            // seem to be stored on a per-database basis. Would the author of pdf support
            // please have a look at it?
            /*
            $get_fields = array('page_descr');
            $where_fields = array('db_name' => $source_db);
            $new_fields = array('db_name' => $target_db);
            $last_id = PMA_duplicate_table_info('pdfwork', 'pdf_pages', $get_fields, $where_fields, $new_fields);
            
            if (isset($last_id) && $last_id >= 0) {
                $get_fields = array('x', 'y');
                $where_fields = array('db_name' => $source_db, 'table_name' => $source_table);
                $new_fields = array('db_name' => $target_db, 'table_name' => $target_table, 'pdf_page_number' => $last_id);
                PMA_duplicate_table_info('pdfwork', 'table_coords', $get_fields, $where_fields, $new_fields);
            }
            */
        }
    }
}
示例#13
0
function SQLFormatPHP($sql)
{
    return PMA_SQP_formatHtml(PMA_SQP_parse($sql));
}
示例#14
0
/**
 * Handles requests for executing a routine
 */
function PMA_RTN_handleExecute()
{
    global $_GET, $_POST, $_REQUEST, $GLOBALS, $db, $cfg;
    /**
     * Handle all user requests other than the default of listing routines
     */
    if (!empty($_REQUEST['execute_routine']) && !empty($_REQUEST['item_name'])) {
        // Build the queries
        $routine = PMA_RTN_getDataFromName($_REQUEST['item_name'], $_REQUEST['item_type'], false);
        if ($routine !== false) {
            $queries = array();
            $end_query = array();
            $args = array();
            for ($i = 0; $i < $routine['item_num_params']; $i++) {
                if (isset($_REQUEST['params'][$routine['item_param_name'][$i]])) {
                    $value = $_REQUEST['params'][$routine['item_param_name'][$i]];
                    if (is_array($value)) {
                        // is SET type
                        $value = implode(',', $value);
                    }
                    $value = PMA_sqlAddSlashes($value);
                    if (!empty($_REQUEST['funcs'][$routine['item_param_name'][$i]]) && in_array($_REQUEST['funcs'][$routine['item_param_name'][$i]], $cfg['Functions'])) {
                        $queries[] = "SET @p{$i}={$_REQUEST['funcs'][$routine['item_param_name'][$i]]}('{$value}');\n";
                    } else {
                        $queries[] = "SET @p{$i}='{$value}';\n";
                    }
                    $args[] = "@p{$i}";
                } else {
                    $args[] = "@p{$i}";
                }
                if ($routine['item_type'] == 'PROCEDURE') {
                    if ($routine['item_param_dir'][$i] == 'OUT' || $routine['item_param_dir'][$i] == 'INOUT') {
                        $end_query[] = "@p{$i} AS " . PMA_backquote($routine['item_param_name'][$i]);
                    }
                }
            }
            if ($routine['item_type'] == 'PROCEDURE') {
                $queries[] = "CALL " . PMA_backquote($routine['item_name']) . "(" . implode(', ', $args) . ");\n";
                if (count($end_query)) {
                    $queries[] = "SELECT " . implode(', ', $end_query) . ";\n";
                }
            } else {
                $queries[] = "SELECT " . PMA_backquote($routine['item_name']) . "(" . implode(', ', $args) . ") " . "AS " . PMA_backquote($routine['item_name']) . ";\n";
            }
            // Execute the queries
            $affected = 0;
            $result = null;
            $outcome = true;
            foreach ($queries as $query) {
                $resource = PMA_DBI_try_query($query);
                if ($resource === false) {
                    $outcome = false;
                    break;
                }
                while (true) {
                    if (!PMA_DBI_more_results()) {
                        break;
                    }
                    PMA_DBI_next_result();
                }
                if (substr($query, 0, 6) == 'SELECT') {
                    $result = $resource;
                } else {
                    if (substr($query, 0, 4) == 'CALL') {
                        $result = $resource ? $resource : $result;
                        $affected = PMA_DBI_affected_rows() - PMA_DBI_num_rows($resource);
                    }
                }
            }
            // Generate output
            if ($outcome) {
                $message = __('Your SQL query has been executed successfully');
                if ($routine['item_type'] == 'PROCEDURE') {
                    $message .= '<br />';
                    $message .= sprintf(_ngettext('%d row affected by the last statement inside the procedure', '%d rows affected by the last statement inside the procedure', $affected), $affected);
                }
                $message = PMA_message::success($message);
                // Pass the SQL queries through the "pretty printer"
                $output = '<code class="sql" style="margin-bottom: 1em;">';
                $output .= PMA_SQP_formatHtml(PMA_SQP_parse(implode($queries)));
                $output .= '</code>';
                // Display results
                if ($result) {
                    $output .= "<fieldset><legend>";
                    $output .= sprintf(__('Execution results of routine %s'), PMA_backquote(htmlspecialchars($routine['item_name'])));
                    $output .= "</legend>";
                    $output .= "<table><tr>";
                    foreach (PMA_DBI_get_fields_meta($result) as $key => $field) {
                        $output .= "<th>";
                        $output .= htmlspecialchars($field->name);
                        $output .= "</th>";
                    }
                    $output .= "</tr>";
                    // Stored routines can only ever return ONE ROW.
                    $data = PMA_DBI_fetch_single_row($result);
                    foreach ($data as $key => $value) {
                        if ($value === null) {
                            $value = '<i>NULL</i>';
                        } else {
                            $value = htmlspecialchars($value);
                        }
                        $output .= "<td class='odd'>" . $value . "</td>";
                    }
                    $output .= "</table></fieldset>";
                } else {
                    $notice = __('MySQL returned an empty result set (i.e. zero rows).');
                    $output .= PMA_message::notice($notice)->getDisplay();
                }
            } else {
                $output = '';
                $message = PMA_message::error(sprintf(__('The following query has failed: "%s"'), $query) . '<br /><br />' . __('MySQL said: ') . PMA_DBI_getError(null));
            }
            // Print/send output
            if ($GLOBALS['is_ajax_request']) {
                $extra_data = array('dialog' => false);
                PMA_ajaxResponse($message->getDisplay() . $output, $message->isSuccess(), $extra_data);
            } else {
                echo $message->getDisplay() . $output;
                if ($message->isError()) {
                    // At least one query has failed, so shouldn't
                    // execute any more queries, so we quit.
                    exit;
                }
                unset($_POST);
                // Now deliberately fall through to displaying the routines list
            }
        } else {
            $message = __('Error in processing request') . ' : ';
            $message .= sprintf(PMA_RTE_getWord('not_found'), htmlspecialchars(PMA_backquote($_REQUEST['item_name'])), htmlspecialchars(PMA_backquote($db)));
            $message = PMA_message::error($message);
            if ($GLOBALS['is_ajax_request']) {
                PMA_ajaxResponse($message, $message->isSuccess());
            } else {
                echo $message->getDisplay();
                unset($_POST);
            }
        }
    } else {
        if (!empty($_GET['execute_dialog']) && !empty($_GET['item_name'])) {
            /**
             * Display the execute form for a routine.
             */
            $routine = PMA_RTN_getDataFromName($_GET['item_name'], $_GET['item_type'], true);
            if ($routine !== false) {
                $form = PMA_RTN_getExecuteForm($routine);
                if ($GLOBALS['is_ajax_request'] == true) {
                    $extra_data = array();
                    $extra_data['dialog'] = true;
                    $extra_data['title'] = __("Execute routine") . " ";
                    $extra_data['title'] .= PMA_backquote(htmlentities($_GET['item_name'], ENT_QUOTES));
                    PMA_ajaxResponse($form, true, $extra_data);
                } else {
                    echo "\n\n<h2>" . __("Execute routine") . "</h2>\n\n";
                    echo $form;
                    include './libraries/footer.inc.php';
                    // exit;
                }
            } else {
                if ($GLOBALS['is_ajax_request'] == true) {
                    $message = __('Error in processing request') . ' : ';
                    $message .= sprintf(PMA_RTE_getWord('not_found'), htmlspecialchars(PMA_backquote($_REQUEST['item_name'])), htmlspecialchars(PMA_backquote($db)));
                    $message = PMA_message::error($message);
                    PMA_ajaxResponse($message, false);
                }
            }
        }
    }
}
示例#15
0
function printServerTraffic()
{
    global $server_status, $PMA_PHP_SELF;
    global $server_master_status, $server_slave_status, $replication_types;
    $hour_factor = 3600 / $server_status['Uptime'];
    /**
     * starttime calculation
     */
    $start_time = PMA_DBI_fetch_value('SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
    ?>
    <h3><?php 
    echo sprintf(__('Network traffic since startup: %s'), implode(' ', PMA_formatByteDown($server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1)));
    ?>
    </h3>

    <p>
    <?php 
    echo sprintf(__('This MySQL server has been running for %1$s. It started up on %2$s.'), PMA_timespanFormat($server_status['Uptime']), PMA_localisedDate($start_time)) . "\n";
    ?>
    </p>

    <?php 
    if ($server_master_status || $server_slave_status) {
        echo '<p class="notice">';
        if ($server_master_status && $server_slave_status) {
            echo __('This MySQL server works as <b>master</b> and <b>slave</b> in <b>replication</b> process.');
        } elseif ($server_master_status) {
            echo __('This MySQL server works as <b>master</b> in <b>replication</b> process.');
        } elseif ($server_slave_status) {
            echo __('This MySQL server works as <b>slave</b> in <b>replication</b> process.');
        }
        echo ' ';
        echo __('For further information about replication status on the server, please visit the <a href="#replication">replication section</a>.');
        echo '</p>';
    }
    /* if the server works as master or slave in replication process, display useful information */
    if ($server_master_status || $server_slave_status) {
        ?>
      <hr class="clearfloat" />

      <h3><a name="replication"></a><?php 
        echo __('Replication status');
        ?>
</h3>
    <?php 
        foreach ($replication_types as $type) {
            if (${"server_{$type}_status"}) {
                PMA_replication_print_status_table($type);
            }
        }
        unset($types);
    }
    ?>

    <table id="serverstatustraffic" class="data noclick">
    <thead>
    <tr>
        <th colspan="2"><?php 
    echo __('Traffic') . '&nbsp;' . PMA_showHint(__('On a busy server, the byte counters may overrun, so those statistics as reported by the MySQL server may be incorrect.'));
    ?>
</th>
        <th>&oslash; <?php 
    echo __('per hour');
    ?>
</th>
    </tr>
    </thead>
    <tbody>
    <tr class="odd">
        <th class="name"><?php 
    echo __('Received');
    ?>
</th>
        <td class="value"><?php 
    echo implode(' ', PMA_formatByteDown($server_status['Bytes_received'], 3, 1));
    ?>
</td>
        <td class="value"><?php 
    echo implode(' ', PMA_formatByteDown($server_status['Bytes_received'] * $hour_factor, 3, 1));
    ?>
</td>
    </tr>
    <tr class="even">
        <th class="name"><?php 
    echo __('Sent');
    ?>
</th>
        <td class="value"><?php 
    echo implode(' ', PMA_formatByteDown($server_status['Bytes_sent'], 3, 1));
    ?>
</td>
        <td class="value"><?php 
    echo implode(' ', PMA_formatByteDown($server_status['Bytes_sent'] * $hour_factor, 3, 1));
    ?>
</td>
    </tr>
    <tr class="odd">
        <th class="name"><?php 
    echo __('Total');
    ?>
</th>
        <td class="value"><?php 
    echo implode(' ', PMA_formatByteDown($server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1));
    ?>
</td>
        <td class="value"><?php 
    echo implode(' ', PMA_formatByteDown(($server_status['Bytes_received'] + $server_status['Bytes_sent']) * $hour_factor, 3, 1));
    ?>
</td>
    </tr>
    </tbody>
    </table>

    <table id="serverstatusconnections" class="data noclick">
    <thead>
    <tr>
        <th colspan="2"><?php 
    echo __('Connections');
    ?>
</th>
        <th>&oslash; <?php 
    echo __('per hour');
    ?>
</th>
        <th>%</th>
    </tr>
    </thead>
    <tbody>
    <tr class="odd">
        <th class="name"><?php 
    echo __('max. concurrent connections');
    ?>
</th>
        <td class="value"><?php 
    echo PMA_formatNumber($server_status['Max_used_connections'], 0);
    ?>
  </td>
        <td class="value">--- </td>
        <td class="value">--- </td>
    </tr>
    <tr class="even">
        <th class="name"><?php 
    echo __('Failed attempts');
    ?>
</th>
        <td class="value"><?php 
    echo PMA_formatNumber($server_status['Aborted_connects'], 4, 1, true);
    ?>
</td>
        <td class="value"><?php 
    echo PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor, 4, 2, true);
    ?>
</td>
        <td class="value"><?php 
    echo $server_status['Connections'] > 0 ? PMA_formatNumber($server_status['Aborted_connects'] * 100 / $server_status['Connections'], 0, 2, true) . '%' : '--- ';
    ?>
</td>
    </tr>
    <tr class="odd">
        <th class="name"><?php 
    echo __('Aborted');
    ?>
</th>
        <td class="value"><?php 
    echo PMA_formatNumber($server_status['Aborted_clients'], 4, 1, true);
    ?>
</td>
        <td class="value"><?php 
    echo PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor, 4, 2, true);
    ?>
</td>
        <td class="value"><?php 
    echo $server_status['Connections'] > 0 ? PMA_formatNumber($server_status['Aborted_clients'] * 100 / $server_status['Connections'], 0, 2, true) . '%' : '--- ';
    ?>
</td>
    </tr>
    <tr class="even">
        <th class="name"><?php 
    echo __('Total');
    ?>
</th>
        <td class="value"><?php 
    echo PMA_formatNumber($server_status['Connections'], 4, 0);
    ?>
</td>
        <td class="value"><?php 
    echo PMA_formatNumber($server_status['Connections'] * $hour_factor, 4, 2);
    ?>
</td>
        <td class="value"><?php 
    echo PMA_formatNumber(100, 0, 2);
    ?>
%</td>
    </tr>
    </tbody>
    </table>
    <?php 
    $url_params = array();
    $show_full_sql = !empty($_REQUEST['full']);
    if ($show_full_sql) {
        $url_params['full'] = 1;
        $full_text_link = 'server_status.php' . PMA_generate_common_url(array(), 'html', '?');
    } else {
        $full_text_link = 'server_status.php' . PMA_generate_common_url(array('full' => 1));
    }
    if (PMA_DRIZZLE) {
        $sql_query = "SELECT\n                p.id       AS Id,\n                p.username AS User,\n                p.host     AS Host,\n                p.db       AS db,\n                p.command  AS Command,\n                p.time     AS Time,\n                p.state    AS State,\n                " . ($show_full_sql ? 's.query' : 'left(p.info, ' . (int) $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'] . ')') . " AS Info\n            FROM data_dictionary.PROCESSLIST p\n                " . ($show_full_sql ? 'LEFT JOIN data_dictionary.SESSIONS s ON s.session_id = p.id' : '');
    } else {
        $sql_query = $show_full_sql ? 'SHOW FULL PROCESSLIST' : 'SHOW PROCESSLIST';
    }
    $result = PMA_DBI_query($sql_query);
    /**
     * Displays the page
     */
    ?>
    <table id="tableprocesslist" class="data clearfloat noclick">
    <thead>
    <tr>
        <th><?php 
    echo __('Processes');
    ?>
</th>
        <th><?php 
    echo __('ID');
    ?>
</th>
        <th><?php 
    echo __('User');
    ?>
</th>
        <th><?php 
    echo __('Host');
    ?>
</th>
        <th><?php 
    echo __('Database');
    ?>
</th>
        <th><?php 
    echo __('Command');
    ?>
</th>
        <th><?php 
    echo __('Time');
    ?>
</th>
        <th><?php 
    echo __('Status');
    ?>
</th>
        <th><?php 
    echo __('SQL query');
    if (!PMA_DRIZZLE) {
        ?>
            <a href="<?php 
        echo $full_text_link;
        ?>
"
                title="<?php 
        echo $show_full_sql ? __('Truncate Shown Queries') : __('Show Full Queries');
        ?>
">
                <img src="<?php 
        echo $GLOBALS['pmaThemeImage'] . 's_' . ($show_full_sql ? 'partial' : 'full');
        ?>
text.png"
                alt="<?php 
        echo $show_full_sql ? __('Truncate Shown Queries') : __('Show Full Queries');
        ?>
" />
            </a>
            <?php 
    }
    ?>
        </th>
    </tr>
    </thead>
    <tbody>
    <?php 
    $odd_row = true;
    while ($process = PMA_DBI_fetch_assoc($result)) {
        $url_params['kill'] = $process['Id'];
        $kill_process = 'server_status.php' . PMA_generate_common_url($url_params);
        ?>
    <tr class="<?php 
        echo $odd_row ? 'odd' : 'even';
        ?>
">
        <td><a href="<?php 
        echo $kill_process;
        ?>
"><?php 
        echo __('Kill');
        ?>
</a></td>
        <td class="value"><?php 
        echo $process['Id'];
        ?>
</td>
        <td><?php 
        echo $process['User'];
        ?>
</td>
        <td><?php 
        echo $process['Host'];
        ?>
</td>
        <td><?php 
        echo !isset($process['db']) || !strlen($process['db']) ? '<i>' . __('None') . '</i>' : $process['db'];
        ?>
</td>
        <td><?php 
        echo $process['Command'];
        ?>
</td>
        <td class="value"><?php 
        echo $process['Time'];
        ?>
</td>
        <td><?php 
        echo empty($process['State']) ? '---' : $process['State'];
        ?>
</td>
        <td>
        <?php 
        if (empty($process['Info'])) {
            echo '---';
        } else {
            if (!$show_full_sql && strlen($process['Info']) > $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
                echo htmlspecialchars(substr($process['Info'], 0, $GLOBALS['cfg']['MaxCharactersInDisplayedSQL'])) . '[...]';
            } else {
                echo PMA_SQP_formatHtml(PMA_SQP_parse($process['Info']));
            }
        }
        ?>
        </td>
    </tr>
        <?php 
        $odd_row = !$odd_row;
    }
    ?>
    </tbody>
    </table>
    <?php 
}
示例#16
0
 /**
  * Copies or renames table
  * @todo use RENAME for move operations
  *        - would work only if the databases are on the same filesystem,
  *          how can we check that? try the operation and
  *          catch an error?
  *        - for views, only if MYSQL > 50013
  *        - still have to handle pmadb synch.
  *
  * @author          Michal Cihar <*****@*****.**>
  */
 function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $move, $mode)
 {
     global $err_url;
     // set export settings we need
     $GLOBALS['sql_backquotes'] = 1;
     $GLOBALS['asfile'] = 1;
     // Ensure the target is valid
     if (!$GLOBALS['PMA_List_Database']->exists($source_db, $target_db)) {
         /**
          * @todo exit really needed here? or just a return?
          */
         exit;
     }
     $source = PMA_backquote($source_db) . '.' . PMA_backquote($source_table);
     if (!isset($target_db) || !strlen($target_db)) {
         $target_db = $source_db;
     }
     // Doing a select_db could avoid some problems with replicated databases,
     // when moving table from replicated one to not replicated one
     PMA_DBI_select_db($target_db);
     $target = PMA_backquote($target_db) . '.' . PMA_backquote($target_table);
     // do not create the table if dataonly
     if ($what != 'dataonly') {
         require_once './libraries/export/sql.php';
         $no_constraints_comments = true;
         $GLOBALS['sql_constraints_query'] = '';
         $sql_structure = PMA_getTableDef($source_db, $source_table, "\n", $err_url);
         unset($no_constraints_comments);
         $parsed_sql = PMA_SQP_parse($sql_structure);
         $analyzed_sql = PMA_SQP_analyze($parsed_sql);
         $i = 0;
         if (empty($analyzed_sql[0]['create_table_fields'])) {
             // this is not a CREATE TABLE, so find the first VIEW
             $target_for_view = PMA_backquote($target_db);
             while (true) {
                 if ($parsed_sql[$i]['type'] == 'alpha_reservedWord' && $parsed_sql[$i]['data'] == 'VIEW') {
                     break;
                 }
                 $i++;
             }
         }
         unset($analyzed_sql);
         $server_sql_mode = PMA_DBI_fetch_value("SHOW VARIABLES LIKE 'sql_mode'", 0, 1);
         if ('ANSI_QUOTES' == $server_sql_mode) {
             $table_delimiter = 'quote_double';
         } else {
             $table_delimiter = 'quote_backtick';
         }
         unset($server_sql_mode);
         /* nijel: Find table name in query and replace it */
         while ($parsed_sql[$i]['type'] != $table_delimiter) {
             $i++;
         }
         /* no need to PMA_backquote() */
         if (isset($target_for_view)) {
             // this a view definition; we just found the first db name
             // that follows DEFINER VIEW
             // so change it for the new db name
             $parsed_sql[$i]['data'] = $target_for_view;
             // then we have to find all references to the source db
             // and change them to the target db, ensuring we stay into
             // the $parsed_sql limits
             $last = $parsed_sql['len'] - 1;
             $backquoted_source_db = PMA_backquote($source_db);
             for (++$i; $i <= $last; $i++) {
                 if ($parsed_sql[$i]['type'] == $table_delimiter && $parsed_sql[$i]['data'] == $backquoted_source_db) {
                     $parsed_sql[$i]['data'] = $target_for_view;
                 }
             }
             unset($last, $backquoted_source_db);
         } else {
             $parsed_sql[$i]['data'] = $target;
         }
         /* Generate query back */
         $sql_structure = PMA_SQP_formatHtml($parsed_sql, 'query_only');
         // If table exists, and 'add drop table' is selected: Drop it!
         $drop_query = '';
         if (isset($GLOBALS['drop_if_exists']) && $GLOBALS['drop_if_exists'] == 'true') {
             if (PMA_Table::_isView($target_db, $target_table)) {
                 $drop_query = 'DROP VIEW';
             } else {
                 $drop_query = 'DROP TABLE';
             }
             $drop_query .= ' IF EXISTS ' . PMA_backquote($target_db) . '.' . PMA_backquote($target_table);
             PMA_DBI_query($drop_query);
             $GLOBALS['sql_query'] .= "\n" . $drop_query . ';';
             // garvin: If an existing table gets deleted, maintain any
             // entries for the PMA_* tables
             $maintain_relations = true;
         }
         @PMA_DBI_query($sql_structure);
         $GLOBALS['sql_query'] .= "\n" . $sql_structure . ';';
         if (($move || isset($GLOBALS['add_constraints'])) && !empty($GLOBALS['sql_constraints_query'])) {
             $parsed_sql = PMA_SQP_parse($GLOBALS['sql_constraints_query']);
             $i = 0;
             // find the first $table_delimiter, it must be the source table name
             while ($parsed_sql[$i]['type'] != $table_delimiter) {
                 $i++;
                 // maybe someday we should guard against going over limit
                 //if ($i == $parsed_sql['len']) {
                 //    break;
                 //}
             }
             // replace it by the target table name, no need to PMA_backquote()
             $parsed_sql[$i]['data'] = $target;
             // now we must remove all $table_delimiter that follow a CONSTRAINT
             // keyword, because a constraint name must be unique in a db
             $cnt = $parsed_sql['len'] - 1;
             for ($j = $i; $j < $cnt; $j++) {
                 if ($parsed_sql[$j]['type'] == 'alpha_reservedWord' && strtoupper($parsed_sql[$j]['data']) == 'CONSTRAINT') {
                     if ($parsed_sql[$j + 1]['type'] == $table_delimiter) {
                         $parsed_sql[$j + 1]['data'] = '';
                     }
                 }
             }
             // Generate query back
             $GLOBALS['sql_constraints_query'] = PMA_SQP_formatHtml($parsed_sql, 'query_only');
             if ($mode == 'one_table') {
                 PMA_DBI_query($GLOBALS['sql_constraints_query']);
             }
             $GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_constraints_query'];
             if ($mode == 'one_table') {
                 unset($GLOBALS['sql_constraints_query']);
             }
         }
     } else {
         $GLOBALS['sql_query'] = '';
     }
     // Copy the data unless this is a VIEW
     if (($what == 'data' || $what == 'dataonly') && !PMA_Table::_isView($target_db, $target_table)) {
         $sql_insert_data = 'INSERT INTO ' . $target . ' SELECT * FROM ' . $source;
         PMA_DBI_query($sql_insert_data);
         $GLOBALS['sql_query'] .= "\n\n" . $sql_insert_data . ';';
     }
     require_once './libraries/relation.lib.php';
     $GLOBALS['cfgRelation'] = PMA_getRelationsParam();
     // Drops old table if the user has requested to move it
     if ($move) {
         // This could avoid some problems with replicated databases, when
         // moving table from replicated one to not replicated one
         PMA_DBI_select_db($source_db);
         if (PMA_Table::_isView($source_db, $source_table)) {
             $sql_drop_query = 'DROP VIEW';
         } else {
             $sql_drop_query = 'DROP TABLE';
         }
         $sql_drop_query .= ' ' . $source;
         PMA_DBI_query($sql_drop_query);
         // garvin: Move old entries from PMA-DBs to new table
         if ($GLOBALS['cfgRelation']['commwork']) {
             $remove_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . ' SET     table_name = \'' . PMA_sqlAddslashes($target_table) . '\', ' . '        db_name    = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
             PMA_query_as_cu($remove_query);
             unset($remove_query);
         }
         // garvin: updating bookmarks is not possible since only a single table is moved,
         // and not the whole DB.
         if ($GLOBALS['cfgRelation']['displaywork']) {
             $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_info']) . ' SET     db_name = \'' . PMA_sqlAddslashes($target_db) . '\', ' . '         table_name = \'' . PMA_sqlAddslashes($target_table) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
             PMA_query_as_cu($table_query);
             unset($table_query);
         }
         if ($GLOBALS['cfgRelation']['relwork']) {
             $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . ' SET     foreign_table = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         foreign_db = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE foreign_db  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND foreign_table = \'' . PMA_sqlAddslashes($source_table) . '\'';
             PMA_query_as_cu($table_query);
             unset($table_query);
             $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['relation']) . ' SET     master_table = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         master_db = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE master_db  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND master_table = \'' . PMA_sqlAddslashes($source_table) . '\'';
             PMA_query_as_cu($table_query);
             unset($table_query);
         }
         /**
          * @todo garvin: Can't get moving PDFs the right way. The page numbers
          * always get screwed up independently from duplication because the
          * numbers do not seem to be stored on a per-database basis. Would
          * the author of pdf support please have a look at it?
          */
         if ($GLOBALS['cfgRelation']['pdfwork']) {
             $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_coords']) . ' SET     table_name = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
             PMA_query_as_cu($table_query);
             unset($table_query);
             /*
             $pdf_query = 'SELECT pdf_page_number '
                        . ' FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['table_coords'])
                        . ' WHERE db_name  = \'' . PMA_sqlAddslashes($target_db) . '\''
                        . ' AND table_name = \'' . PMA_sqlAddslashes($target_table) . '\'';
             $pdf_rs = PMA_query_as_cu($pdf_query);
             
             while ($pdf_copy_row = PMA_DBI_fetch_assoc($pdf_rs)) {
                 $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['pdf_pages'])
                                 . ' SET     db_name = \'' . PMA_sqlAddslashes($target_db) . '\''
                                 . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\''
                                 . ' AND page_nr = \'' . PMA_sqlAddslashes($pdf_copy_row['pdf_page_number']) . '\'';
                 $tb_rs    = PMA_query_as_cu($table_query);
                 unset($table_query);
                 unset($tb_rs);
             }
             */
         }
         if ($GLOBALS['cfgRelation']['designerwork']) {
             $table_query = 'UPDATE ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['designer_coords']) . ' SET     table_name = \'' . PMA_sqlAddslashes($target_table) . '\',' . '         db_name = \'' . PMA_sqlAddslashes($target_db) . '\'' . ' WHERE db_name  = \'' . PMA_sqlAddslashes($source_db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
             PMA_query_as_cu($table_query);
             unset($table_query);
         }
         $GLOBALS['sql_query'] .= "\n\n" . $sql_drop_query . ';';
         // end if ($move)
     } else {
         // we are copying
         // garvin: Create new entries as duplicates from old PMA DBs
         if ($what != 'dataonly' && !isset($maintain_relations)) {
             if ($GLOBALS['cfgRelation']['commwork']) {
                 // Get all comments and MIME-Types for current table
                 $comments_copy_query = 'SELECT
                                             column_name, ' . PMA_backquote('comment') . ($GLOBALS['cfgRelation']['mimework'] ? ', mimetype, transformation, transformation_options' : '') . '
                                         FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . '
                                         WHERE
                                             db_name = \'' . PMA_sqlAddslashes($source_db) . '\' AND
                                             table_name = \'' . PMA_sqlAddslashes($source_table) . '\'';
                 $comments_copy_rs = PMA_query_as_cu($comments_copy_query);
                 // Write every comment as new copied entry. [MIME]
                 while ($comments_copy_row = PMA_DBI_fetch_assoc($comments_copy_rs)) {
                     $new_comment_query = 'REPLACE INTO ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ($GLOBALS['cfgRelation']['mimework'] ? ', mimetype, transformation, transformation_options' : '') . ') ' . ' VALUES(' . '\'' . PMA_sqlAddslashes($target_db) . '\',' . '\'' . PMA_sqlAddslashes($target_table) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['column_name']) . '\'' . ($GLOBALS['cfgRelation']['mimework'] ? ',\'' . PMA_sqlAddslashes($comments_copy_row['comment']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['mimetype']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['transformation']) . '\',' . '\'' . PMA_sqlAddslashes($comments_copy_row['transformation_options']) . '\'' : '') . ')';
                     PMA_query_as_cu($new_comment_query);
                 }
                 // end while
                 PMA_DBI_free_result($comments_copy_rs);
                 unset($comments_copy_rs);
             }
             // duplicating the bookmarks must not be done here, but
             // just once per db
             $get_fields = array('display_field');
             $where_fields = array('db_name' => $source_db, 'table_name' => $source_table);
             $new_fields = array('db_name' => $target_db, 'table_name' => $target_table);
             PMA_Table::duplicateInfo('displaywork', 'table_info', $get_fields, $where_fields, $new_fields);
             /**
              * @todo revise this code when we support cross-db relations
              */
             $get_fields = array('master_field', 'foreign_table', 'foreign_field');
             $where_fields = array('master_db' => $source_db, 'master_table' => $source_table);
             $new_fields = array('master_db' => $target_db, 'foreign_db' => $target_db, 'master_table' => $target_table);
             PMA_Table::duplicateInfo('relwork', 'relation', $get_fields, $where_fields, $new_fields);
             $get_fields = array('foreign_field', 'master_table', 'master_field');
             $where_fields = array('foreign_db' => $source_db, 'foreign_table' => $source_table);
             $new_fields = array('master_db' => $target_db, 'foreign_db' => $target_db, 'foreign_table' => $target_table);
             PMA_Table::duplicateInfo('relwork', 'relation', $get_fields, $where_fields, $new_fields);
             $get_fields = array('x', 'y', 'v', 'h');
             $where_fields = array('db_name' => $source_db, 'table_name' => $source_table);
             $new_fields = array('db_name' => $target_db, 'table_name' => $target_table);
             PMA_Table::duplicateInfo('designerwork', 'designer_coords', $get_fields, $where_fields, $new_fields);
             /**
             * @todo garvin: Can't get duplicating PDFs the right way. The
             * page numbers always get screwed up independently from
             * duplication because the numbers do not seem to be stored on a
             * per-database basis. Would the author of pdf support please
             * have a look at it?
             *
                             $get_fields = array('page_descr');
                             $where_fields = array('db_name' => $source_db);
                             $new_fields = array('db_name' => $target_db);
                             $last_id = PMA_Table::duplicateInfo('pdfwork', 'pdf_pages', $get_fields, $where_fields, $new_fields);
             
                             if (isset($last_id) && $last_id >= 0) {
                $get_fields = array('x', 'y');
                $where_fields = array('db_name' => $source_db, 'table_name' => $source_table);
                $new_fields = array('db_name' => $target_db, 'table_name' => $target_table, 'pdf_page_number' => $last_id);
                PMA_Table::duplicateInfo('pdfwork', 'table_coords', $get_fields, $where_fields, $new_fields);
                             }
             */
         }
     }
 }
示例#17
0
         if (isset($sql_query)) {
             $sql_query .= "\n" . $sql_structure . ';';
         } else {
             $sql_query = $sql_structure . ';';
         }
     }
     if ((isset($submit_move) || isset($constraints)) && isset($sql_constraints)) {
         $parsed_sql = PMA_SQP_parse($sql_constraints);
         $i = 0;
         while ($parsed_sql[$i]['type'] != 'quote_backtick') {
             $i++;
         }
         /* no need to PMA_backquote() */
         $parsed_sql[$i]['data'] = $target;
         /* Generate query back */
         $sql_constraints = PMA_SQP_formatHtml($parsed_sql, 'query_only');
         $result = @PMA_mysql_query($sql_constraints);
         if (PMA_mysql_error()) {
             require_once './header.inc.php';
             PMA_mysqlDie('', $sql_structure, '', $err_url);
         } else {
             if (isset($sql_query)) {
                 $sql_query .= "\n" . $sql_constraints;
             } else {
                 $sql_query = $sql_constraints;
             }
         }
     }
 } else {
     $sql_query = '';
 }
示例#18
0
/**
 * Handles requests for executing a routine
 *
 * @return Does not return
 */
function PMA_RTN_handleExecute()
{
    global $_GET, $_POST, $_REQUEST, $GLOBALS, $db;
    /**
     * Handle all user requests other than the default of listing routines
     */
    if (!empty($_REQUEST['execute_routine']) && !empty($_REQUEST['item_name'])) {
        // Build the queries
        $routine = PMA_RTN_getDataFromName($_REQUEST['item_name'], $_REQUEST['item_type'], false);
        if ($routine !== false) {
            $queries = array();
            $end_query = array();
            $args = array();
            $all_functions = $GLOBALS['PMA_Types']->getAllFunctions();
            for ($i = 0; $i < $routine['item_num_params']; $i++) {
                if (isset($_REQUEST['params'][$routine['item_param_name'][$i]])) {
                    $value = $_REQUEST['params'][$routine['item_param_name'][$i]];
                    if (is_array($value)) {
                        // is SET type
                        $value = implode(',', $value);
                    }
                    $value = PMA_Util::sqlAddSlashes($value);
                    if (!empty($_REQUEST['funcs'][$routine['item_param_name'][$i]]) && in_array($_REQUEST['funcs'][$routine['item_param_name'][$i]], $all_functions)) {
                        $queries[] = "SET @p{$i}={$_REQUEST['funcs'][$routine['item_param_name'][$i]]}('{$value}');\n";
                    } else {
                        $queries[] = "SET @p{$i}='{$value}';\n";
                    }
                    $args[] = "@p{$i}";
                } else {
                    $args[] = "@p{$i}";
                }
                if ($routine['item_type'] == 'PROCEDURE') {
                    if ($routine['item_param_dir'][$i] == 'OUT' || $routine['item_param_dir'][$i] == 'INOUT') {
                        $end_query[] = "@p{$i} AS " . PMA_Util::backquote($routine['item_param_name'][$i]);
                    }
                }
            }
            if ($routine['item_type'] == 'PROCEDURE') {
                $queries[] = "CALL " . PMA_Util::backquote($routine['item_name']) . "(" . implode(', ', $args) . ");\n";
                if (count($end_query)) {
                    $queries[] = "SELECT " . implode(', ', $end_query) . ";\n";
                }
            } else {
                $queries[] = "SELECT " . PMA_Util::backquote($routine['item_name']) . "(" . implode(', ', $args) . ") " . "AS " . PMA_Util::backquote($routine['item_name']) . ";\n";
            }
            // Get all the queries as one SQL statement
            $multiple_query = implode("", $queries);
            $outcome = true;
            $affected = 0;
            // Execute query
            if (!PMA_DBI_try_multi_query($multiple_query)) {
                $outcome = false;
            }
            // Generate output
            if ($outcome) {
                // Pass the SQL queries through the "pretty printer"
                $output = '<code class="sql" style="margin-bottom: 1em;">';
                $output .= PMA_SQP_formatHtml(PMA_SQP_parse(implode($queries)));
                $output .= '</code>';
                // Display results
                $output .= "<fieldset><legend>";
                $output .= sprintf(__('Execution results of routine %s'), PMA_Util::backquote(htmlspecialchars($routine['item_name'])));
                $output .= "</legend>";
                $num_of_rusults_set_to_display = 0;
                do {
                    $result = PMA_DBI_store_result();
                    $num_rows = PMA_DBI_num_rows($result);
                    if ($result !== false && $num_rows > 0) {
                        $output .= "<table><tr>";
                        foreach (PMA_DBI_get_fields_meta($result) as $key => $field) {
                            $output .= "<th>";
                            $output .= htmlspecialchars($field->name);
                            $output .= "</th>";
                        }
                        $output .= "</tr>";
                        $color_class = 'odd';
                        while ($row = PMA_DBI_fetch_assoc($result)) {
                            $output .= "<tr>";
                            foreach ($row as $key => $value) {
                                if ($value === null) {
                                    $value = '<i>NULL</i>';
                                } else {
                                    $value = htmlspecialchars($value);
                                }
                                $output .= "<td class='" . $color_class . "'>" . $value . "</td>";
                            }
                            $output .= "</tr>";
                            $color_class = $color_class == 'odd' ? 'even' : 'odd';
                        }
                        $output .= "</table>";
                        $num_of_rusults_set_to_display++;
                        $affected = $num_rows;
                    }
                    if (!PMA_DBI_more_results()) {
                        break;
                    }
                    $output .= "<br/>";
                    PMA_DBI_free_result($result);
                } while (PMA_DBI_next_result());
                $output .= "</fieldset>";
                $message = __('Your SQL query has been executed successfully');
                if ($routine['item_type'] == 'PROCEDURE') {
                    $message .= '<br />';
                    // TODO : message need to be modified according to the
                    // output from the routine
                    $message .= sprintf(_ngettext('%d row affected by the last statement inside the procedure', '%d rows affected by the last statement inside the procedure', $affected), $affected);
                }
                $message = PMA_message::success($message);
                if ($num_of_rusults_set_to_display == 0) {
                    $notice = __('MySQL returned an empty result set (i.e. zero rows).');
                    $output .= PMA_message::notice($notice)->getDisplay();
                }
            } else {
                $output = '';
                $message = PMA_message::error(sprintf(__('The following query has failed: "%s"'), htmlspecialchars($query)) . '<br /><br />' . __('MySQL said: ') . PMA_DBI_getError(null));
            }
            // Print/send output
            if ($GLOBALS['is_ajax_request']) {
                $response = PMA_Response::getInstance();
                $response->isSuccess($message->isSuccess());
                $response->addJSON('message', $message->getDisplay() . $output);
                $response->addJSON('dialog', false);
                exit;
            } else {
                echo $message->getDisplay() . $output;
                if ($message->isError()) {
                    // At least one query has failed, so shouldn't
                    // execute any more queries, so we quit.
                    exit;
                }
                unset($_POST);
                // Now deliberately fall through to displaying the routines list
            }
        } else {
            $message = __('Error in processing request') . ' : ';
            $message .= sprintf(PMA_RTE_getWord('not_found'), htmlspecialchars(PMA_Util::backquote($_REQUEST['item_name'])), htmlspecialchars(PMA_Util::backquote($db)));
            $message = PMA_message::error($message);
            if ($GLOBALS['is_ajax_request']) {
                $response = PMA_Response::getInstance();
                $response->isSuccess(false);
                $response->addJSON('message', $message);
                exit;
            } else {
                echo $message->getDisplay();
                unset($_POST);
            }
        }
    } else {
        if (!empty($_GET['execute_dialog']) && !empty($_GET['item_name'])) {
            /**
             * Display the execute form for a routine.
             */
            $routine = PMA_RTN_getDataFromName($_GET['item_name'], $_GET['item_type'], true);
            if ($routine !== false) {
                $form = PMA_RTN_getExecuteForm($routine);
                if ($GLOBALS['is_ajax_request'] == true) {
                    $title = __("Execute routine") . " " . PMA_Util::backquote(htmlentities($_GET['item_name'], ENT_QUOTES));
                    $response = PMA_Response::getInstance();
                    $response->addJSON('message', $form);
                    $response->addJSON('title', $title);
                    $response->addJSON('dialog', true);
                } else {
                    echo "\n\n<h2>" . __("Execute routine") . "</h2>\n\n";
                    echo $form;
                }
                exit;
            } else {
                if ($GLOBALS['is_ajax_request'] == true) {
                    $message = __('Error in processing request') . ' : ';
                    $message .= sprintf(PMA_RTE_getWord('not_found'), htmlspecialchars(PMA_Util::backquote($_REQUEST['item_name'])), htmlspecialchars(PMA_Util::backquote($db)));
                    $message = PMA_message::error($message);
                    $response = PMA_Response::getInstance();
                    $response->isSuccess(false);
                    $response->addJSON('message', $message);
                    exit;
                }
            }
        }
    }
}
<?php
$odd_row = true;
while($process = PMA_DBI_fetch_assoc($result)) {
    $url_params['kill'] = $process['Id'];
    $kill_process = 'server_processlist.php' . PMA_generate_common_url($url_params);
    ?>
<tr class="<?php echo $odd_row ? 'odd' : 'even'; ?>">
    <td><a href="<?php echo $kill_process ; ?>"><?php echo $strKill; ?></a></td>
    <td class="value"><?php echo $process['Id']; ?></td>
    <td><?php echo $process['User']; ?></td>
    <td><?php echo $process['Host']; ?></td>
    <td><?php echo ((! isset($process['db']) || ! strlen($process['db'])) ? '<i>' . $strNone . '</i>' : $process['db']); ?></td>
    <td><?php echo $process['Command']; ?></td>
    <td class="value"><?php echo $process['Time']; ?></td>
    <td><?php echo (empty($process['State']) ? '---' : $process['State']); ?></td>
    <td><?php echo (empty($process['Info']) ? '---' : PMA_SQP_formatHtml(PMA_SQP_parse($process['Info']))); ?></td>
</tr>
    <?php
    $odd_row = ! $odd_row;
}
?>
</tbody>
</table>
<?php

/**
 * Sends the footer
 */
require_once './libraries/footer.inc.php';
?>