⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 db_operations.php

📁 phpMyAdmin图形界面化操作,我已经配置好了,只要把解要压缩后的文件放到站点下就可以用了
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/* vim: set expandtab sw=4 ts=4 sts=4: *//** * handles miscellaneous db operations: *  - move/rename *  - copy *  - changing collation *  - changing comment *  - adding tables *  - viewing PDF schemas * * @version $Id: db_operations.php 12011 2008-11-28 12:47:41Z nijel $ *//** * requirements */require_once './libraries/common.inc.php';require_once './libraries/Table.class.php';require_once './libraries/mysql_charsets.lib.php';// add blobstreaming library functionsrequire_once "./libraries/blobstreaming.lib.php";/** * Rename/move or copy database */if (strlen($db) && (! empty($db_rename) || ! empty($db_copy))) {    if (! empty($db_rename)) {        $move = true;    } else {        $move = false;    }    if (!isset($newname) || !strlen($newname)) {        $message = PMA_Message::error('strDatabaseEmpty');    } else {        $sql_query = ''; // in case target db exists        $_error = false;        if ($move ||         (isset($create_database_before_copying) && $create_database_before_copying)) {            // lower_case_table_names=1 `DB` becomes `db`            $lower_case_table_names = PMA_DBI_fetch_value('SHOW VARIABLES LIKE "lower_case_table_names"', 0, 1);            if ($lower_case_table_names === '1') {                $newname = strtolower($newname);            }            $local_query = 'CREATE DATABASE ' . PMA_backquote($newname);            if (isset($db_collation)) {                $local_query .= ' DEFAULT' . PMA_generateCharsetQueryPart($db_collation);            }            $local_query .= ';';            $sql_query = $local_query;            PMA_DBI_query($local_query);            // rebuild the database list because PMA_Table::moveCopy            // checks in this list if the target db exists            $GLOBALS['pma']->databases->build();        }        if (isset($GLOBALS['add_constraints'])) {            $GLOBALS['sql_constraints_query_full_db'] = '';        }        $tables_full = PMA_DBI_get_tables_full($db);        $views = array();        foreach ($tables_full as $each_table => $tmp) {            // to be able to rename a db containing views, we            // first collect in $views all the views we find and we            // will handle them after the tables            /**             * @todo support a view of a view             * @todo support triggers              */            if (PMA_Table::isView($db, $each_table)) {                $views[] = $each_table;                continue;            }            $back = $sql_query;            $sql_query = '';            // value of $what for this table only            $this_what = $what;            // do not copy the data from a Merge table            // note: on the calling FORM, 'data' means 'structure and data'            if ($tables_full[$each_table]['Engine'] == 'MRG_MyISAM') {                if ($this_what == 'data') {                    $this_what = 'structure';                }                if ($this_what == 'dataonly') {                    $this_what = 'nocopy';                }            }            if ($this_what != 'nocopy') {                if (! PMA_Table::moveCopy($db, $each_table, $newname, $each_table,                    isset($this_what) ? $this_what : 'data', $move, 'db_copy'))                {                    $_error = true;                    // $sql_query is filled by PMA_Table::moveCopy()                    $sql_query = $back . $sql_query;                    break;                }                if (isset($GLOBALS['add_constraints'])) {                    $GLOBALS['sql_constraints_query_full_db'] .= $GLOBALS['sql_constraints_query'];                    unset($GLOBALS['sql_constraints_query']);                }            }            // $sql_query is filled by PMA_Table::moveCopy()            $sql_query = $back . $sql_query;        } // end (foreach)        unset($each_table);        // handle the views        if (! $_error) {            foreach ($views as $view) {                if (! PMA_Table::moveCopy($db, $view, $newname, $view,                 'structure', $move, 'db_copy')) {                    $_error = true;                    break;                }            }        }        unset($view, $views);        // now that all tables exist, create all the accumulated constraints        if (! $_error && isset($GLOBALS['add_constraints'])) {            /**             * @todo this works with mysqli but not with mysql, because             * mysql extension does not accept more than one statement; maybe             * interface with the sql import plugin that handles statement delimiter             */            PMA_DBI_query($GLOBALS['sql_constraints_query_full_db']);            // and prepare to display them            $GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_constraints_query_full_db'];            unset($GLOBALS['sql_constraints_query_full_db']);        }        if (PMA_MYSQL_INT_VERSION >= 50000) {            // here I don't use DELIMITER because it's not part of the            // language; I have to send each statement one by one            // to avoid selecting alternatively the current and new db            // we would need to modify the CREATE definitions to qualify            // the db name            $procedure_names = PMA_DBI_get_procedures_or_functions($db, 'PROCEDURE');            if ($procedure_names) {                foreach($procedure_names as $procedure_name) {                    PMA_DBI_select_db($db);                    $tmp_query = PMA_DBI_get_definition($db, 'PROCEDURE', $procedure_name);                    // collect for later display                    $GLOBALS['sql_query'] .= "\n" . $tmp_query;                    PMA_DBI_select_db($newname);                    PMA_DBI_query($tmp_query);                }            }            $function_names = PMA_DBI_get_procedures_or_functions($db, 'FUNCTION');            if ($function_names) {                foreach($function_names as $function_name) {                    PMA_DBI_select_db($db);                    $tmp_query = PMA_DBI_get_definition($db, 'FUNCTION', $function_name);                    // collect for later display                    $GLOBALS['sql_query'] .= "\n" . $tmp_query;                    PMA_DBI_select_db($newname);                    PMA_DBI_query($tmp_query);                }            }        }        // go back to current db, just in case        PMA_DBI_select_db($db);        // Duplicate the bookmarks for this db (done once for each db)        if (! $_error && $db != $newname) {            $get_fields = array('user', 'label', 'query');            $where_fields = array('dbase' => $db);            $new_fields = array('dbase' => $newname);            PMA_Table::duplicateInfo('bookmarkwork', 'bookmark', $get_fields,                $where_fields, $new_fields);        }        if (! $_error && $move) {            // cleanup pmadb stuff for this db            require_once './libraries/relation_cleanup.lib.php';            PMA_relationsCleanupDatabase($db);            // if someday the RENAME DATABASE reappears, do not DROP            $local_query = 'DROP DATABASE ' . PMA_backquote($db) . ';';            $sql_query .= "\n" . $local_query;            PMA_DBI_query($local_query);            $message = PMA_Message::success('strRenameDatabaseOK');            $message->addParam($db);            $message->addParam($newname);        } elseif (! $_error)  {            $message = PMA_Message::success('strCopyDatabaseOK');            $message->addParam($db);            $message->addParam($newname);        }        $reload     = true;        /* Change database to be used */        if (! $_error && $move) {            $db = $newname;        } elseif (! $_error) {            if (isset($switch_to_new) && $switch_to_new == 'true') {                PMA_setCookie('pma_switch_to_new', 'true');                $db = $newname;            } else {                PMA_setCookie('pma_switch_to_new', '');            }        }        if ($_error && ! isset($message)) {            $message = PMA_Message::error();        }    }}/* * Enable/Disable/Repair BLOB Repository Monitoring for current database*/if (strlen($db) > 0 && !empty($db_blob_streaming_op)){    // load PMA_Config    $PMA_Config = $_SESSION['PMA_Config'];    if (!empty($PMA_Config))    {        if ($PMA_Config->get('PBXT_NAME') !== strtolower($db))        {            // if Blobstreaming plugins exist, begin checking for Blobstreaming tables            if ($PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST'))            {                $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');                $bs_tables = $bs_tables[$db];                $oneBSTableExists = FALSE;                // check if at least one blobstreaming table exists                foreach ($bs_tables as $table_key=>$tbl)                    if ($bs_tables[$table_key]['Exists'])                    {                        $oneBSTableExists = TRUE;                        break;                    }                switch ($db_blob_streaming_op)                {                    // enable BLOB repository monitoring                    case "enable":                        // if blobstreaming tables do not exist, create them                        if (!$oneBSTableExists)                            PMA_BS_CreateTables($db);                    break;                    // disable BLOB repository monitoring                    case "disable":                        // if at least one blobstreaming table exists, execute drop                        if ($oneBSTableExists)                            PMA_BS_DropTables($db);                    break;                    // repair BLOB repository                    case "repair":                        // check if a blobstreaming table is missing                        foreach ($bs_tables as $table_key=>$tbl)                        if (!$bs_tables[$table_key]['Exists'])                        {                            PMA_DBI_select_db($db);                            PMA_DBI_query(PMA_BS_GetTableStruct($table_key));                        }                }                // refresh side menu                PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . 'db_operations.php?' . PMA_generate_common_url ('','', '&') . (isset($db) ? '&db=' . urlencode($db) : '') . (isset($token) ? '&token=' . urlencode($token) : '') . (isset($goto) ? '&goto=' . urlencode($goto) : '') . 'reload=1&purge=1');            }   // end  if ($PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST'))        }   // end if ($PMA_Config->get('PBXT_NAME') !== strtolower($db))    }}/** * Settings for relations stuff */require_once './libraries/relation.lib.php';$cfgRelation = PMA_getRelationsParam();/** * Check if comments were updated * (must be done before displaying the menu tabs) */if (isset($_REQUEST['comment'])) {    PMA_setDbComment($db, $comment);}/** * Prepares the tables list if the user where not redirected to this script * because there is no table in the database ($is_info is true) */if (empty($is_info)) {    require './libraries/db_common.inc.php';    $url_query .= '&amp;goto=db_operations.php';    // Gets the database structure    $sub_part = '_structure';    require './libraries/db_info.inc.php';    echo "\n";    if (isset($message)) {        PMA_showMessage($message, $sql_query);        unset($message);    }}$db_collation = PMA_getDbCollation($db);if ($db == 'information_schema') {    $is_information_schema = true;} else {    $is_information_schema = false;}if (!$is_information_schema) {    require './libraries/display_create_table.lib.php';    if ($cfgRelation['commwork']) {        /**         * database comment         */        ?>    <form method="post" action="db_operations.php">    <?php echo PMA_generate_common_hidden_inputs($db); ?>    <fieldset>        <legend>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -