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

📄 db_operations.php

📁 一个用PHP编写的
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/* $Id: db_operations.php 9696 2006-11-13 08:30:25Z nijel $ */// vim: expandtab sw=4 ts=4 sts=4:/** * handles miscellaneous db operations: *  - move/rename *  - copy *  - changing collation *  - changing comment *  - adding tables *  - viewing PDF schemas *//** * requirements */require_once './libraries/common.lib.php';require_once './libraries/Table.class.php';require_once './libraries/mysql_charsets.lib.php';/** * Rename/move or copy database */if (isset($db) &&    ((isset($db_rename) && $db_rename == 'true') ||    (isset($db_copy) && $db_copy == 'true'))) {    if (isset($db_rename) && $db_rename == 'true') {        $move = true;    } else {        $move = false;    }    if (!isset($newname) || !strlen($newname)) {        $message = $strDatabaseEmpty;    } else {        $sql_query = ''; // in case target db exists        if ($move ||           (isset($create_database_before_copying) && $create_database_before_copying)) {            $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_List_Database']->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 $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             */            if (PMA_Table::isView($db, $table)) {                $views[] = $table;                continue;            }            $back = $sql_query;            $sql_query = '';            // value of $what for this table only            $this_what = $what;            if (!isset($tables_full[$table]['Engine'])) {                $tables_full[$table]['Engine'] = $tables_full[$table]['Type'];            }            // do not copy the data from a Merge table            // note: on the calling FORM, 'data' means 'structure and data'            if ($tables_full[$table]['Engine'] == 'MRG_MyISAM') {                if ($this_what == 'data') {                    $this_what = 'structure';                }                if ($this_what == 'dataonly') {                    $this_what = 'nocopy';                }            }            if ($this_what != 'nocopy') {                PMA_Table::moveCopy($db, $table, $newname, $table,                    isset($this_what) ? $this_what : 'data', $move, 'db_copy');                if (isset($GLOBALS['add_constraints'])) {                    $GLOBALS['sql_constraints_query_full_db'] .= $GLOBALS['sql_constraints_query'];                    unset($GLOBALS['sql_constraints_query']);                }            }            $sql_query = $back . $sql_query;        } // end (foreach)        unset($table);        // handle the views        foreach ($views as $view) {            PMA_Table::moveCopy($db, $view, $newname, $view,                'structure', $move, 'db_copy');        }        unset($view, $views);        // now that all tables exist, create all the accumulated constraints        if (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']);        }        // Duplicate the bookmarks for this db (done once for each db)        if ($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 ($move) {            // cleanup pmadb stuff for this db            require_once './libraries/relation_cleanup.lib.php';            PMA_relationsCleanupDatabase($db);            $local_query = 'DROP DATABASE ' . PMA_backquote($db) . ';';            $sql_query .= "\n" . $local_query;            PMA_DBI_query($local_query);            $message    = sprintf($strRenameDatabaseOK, htmlspecialchars($db),                htmlspecialchars($newname));        } else {            $message    = sprintf($strCopyDatabaseOK, htmlspecialchars($db),                htmlspecialchars($newname));        }        $reload     = true;        /* Change database to be used */        if ($move) {            $db         = $newname;        } else {            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', '');            }        }    }}/** * 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 ($cfgRelation['commwork'] && isset($db_comment) && $db_comment == 'true') {    PMA_SetComment($db, '', '(db_comment)', $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 (PMA_MYSQL_INT_VERSION >= 40101) {    $db_collation = PMA_getDbCollation($db);}if (PMA_MYSQL_INT_VERSION < 50002  || (PMA_MYSQL_INT_VERSION >= 50002 && $db != 'information_schema')) {    $is_information_schema = false;} else {    $is_information_schema = true;}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); ?>    <input type="hidden" name="db_comment" value="true" />    <fieldset>        <legend>        <?php        if ($cfg['PropertiesIconic']) {            echo '<img class="icon" src="' . $pmaThemeImage . 'b_comment.png"'                .' alt="" border="0" width="16" height="16" hspace="2" align="middle" />';        }        echo $strDBComment;        $comment = PMA_getComments($db);        ?>        </legend>        <input type="text" name="comment" class="textfield" size="30"            value="<?php            echo (isset($comment) && is_array($comment)                ? htmlspecialchars(implode(' ', $comment))                : ''); ?>" />        <input type="submit" value="<?php echo $strGo; ?>" />    </fieldset>    </form>        <?php    }    /**     * rename database     */    ?>    <form method="post" action="db_operations.php"        onsubmit="return emptyFormElements(this, 'newname')">

⌨️ 快捷键说明

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