📄 sql.php
字号:
<?php/* vim: set expandtab sw=4 ts=4 sts=4: *//** * Set of functions used to build SQL dumps of tables * * @version $Id: sql.php 12010 2008-11-28 12:28:49Z nijel $ */if (! defined('PHPMYADMIN')) { exit;}/** * */if (isset($plugin_list)) { $hide_sql = false; $hide_structure = false; if ($plugin_param['export_type'] == 'table' && !$plugin_param['single_table']) { $hide_structure = true; $hide_sql = true; } if (!$hide_sql) { $plugin_list['sql'] = array( 'text' => 'strSQL', 'extension' => 'sql', 'mime_type' => 'text/x-sql', 'options' => array( array('type' => 'text', 'name' => 'header_comment', 'text' => 'strAddHeaderComment'), array('type' => 'bool', 'name' => 'include_comments', 'text' => 'strComments'), array('type' => 'bool', 'name' => 'use_transaction', 'text' => 'strEncloseInTransaction'), array('type' => 'bool', 'name' => 'disable_fk', 'text' => 'strDisableForeignChecks'), ), 'options_text' => 'strOptions', ); $compats = PMA_DBI_getCompatibilities(); if (count($compats) > 0) { $values = array(); foreach($compats as $val) { $values[$val] = $val; } $plugin_list['sql']['options'][] = array('type' => 'select', 'name' => 'compatibility', 'text' => 'strSQLCompatibility', 'values' => $values, 'doc' => array('manual_MySQL_Database_Administration', 'Server_SQL_mode')); unset($values); } /* Server export options */ if ($plugin_param['export_type'] == 'server') { $plugin_list['sql']['options'][] = array('type' => 'bgroup', 'text' => 'strDatabaseExportOptions'); $plugin_list['sql']['options'][] = array('type' => 'bool', 'name' => 'drop_database', 'text' => sprintf($GLOBALS['strAddClause'], 'DROP DATABASE')); $plugin_list['sql']['options'][] = array('type' => 'egroup'); } /* Structure options */ if (!$hide_structure) { $plugin_list['sql']['options'][] = array('type' => 'bgroup', 'name' => 'structure', 'text' => 'strStructure', 'force' => 'data'); if ($plugin_param['export_type'] == 'table') { if (PMA_Table::isView($GLOBALS['db'], $GLOBALS['table'])) { $drop_clause = 'DROP VIEW'; } else { $drop_clause = 'DROP TABLE'; } } else { $drop_clause = 'DROP TABLE / VIEW / PROCEDURE / FUNCTION'; if (PMA_MYSQL_INT_VERSION > 50100) { $drop_clause .= ' / EVENT'; } } $plugin_list['sql']['options'][] = array('type' => 'bool', 'name' => 'drop_table', 'text' => sprintf($GLOBALS['strAddClause'], $drop_clause)); $plugin_list['sql']['options'][] = array('type' => 'bool', 'name' => 'if_not_exists', 'text' => sprintf($GLOBALS['strAddClause'], 'IF NOT EXISTS')); $plugin_list['sql']['options'][] = array('type' => 'bool', 'name' => 'auto_increment', 'text' => 'strAddAutoIncrement'); $plugin_list['sql']['options'][] = array('type' => 'bool', 'name' => 'backquotes', 'text' => 'strUseBackquotes'); $plugin_list['sql']['options'][] = array('type' => 'bool', 'name' => 'procedure_function', 'text' => sprintf($GLOBALS['strAddClause'], 'CREATE PROCEDURE / FUNCTION' . (PMA_MYSQL_INT_VERSION > 50100 ? ' / EVENT' : ''))); /* MIME stuff etc. */ $plugin_list['sql']['options'][] = array('type' => 'bgroup', 'text' => 'strAddIntoComments'); $plugin_list['sql']['options'][] = array('type' => 'bool', 'name' => 'dates', 'text' => 'strCreationDates'); if (!empty($GLOBALS['cfgRelation']['relation'])) { $plugin_list['sql']['options'][] = array('type' => 'bool', 'name' => 'relation', 'text' => 'strRelations'); } if (!empty($GLOBALS['cfgRelation']['mimework'])) { $plugin_list['sql']['options'][] = array('type' => 'bool', 'name' => 'mime', 'text' => 'strMIME_MIMEtype'); } $plugin_list['sql']['options'][] = array('type' => 'egroup'); $plugin_list['sql']['options'][] = array('type' => 'egroup'); } /* Data */ $plugin_list['sql']['options'][] = array('type' => 'bgroup', 'name' => 'data', 'text' => 'strData', 'force' => 'structure'); $plugin_list['sql']['options'][] = array('type' => 'bool', 'name' => 'columns', 'text' => 'strCompleteInserts', 'doc' => array('programs', 'mysqldump', 'option_mysqldump_complete-insert-option')); $plugin_list['sql']['options'][] = array('type' => 'bool', 'name' => 'extended', 'text' => 'strExtendedInserts', 'doc' => array('programs', 'mysqldump', 'option_mysqldump_extended-insert-option')); $plugin_list['sql']['options'][] = array('type' => 'text', 'name' => 'max_query_size', 'text' => 'strMaximalQueryLength'); $plugin_list['sql']['options'][] = array('type' => 'bool', 'name' => 'delayed', 'text' => 'strDelayedInserts'); $plugin_list['sql']['options'][] = array('type' => 'bool', 'name' => 'ignore', 'text' => 'strIgnoreInserts'); $plugin_list['sql']['options'][] = array('type' => 'bool', 'name' => 'hex_for_blob', 'text' => 'strHexForBLOB'); $plugin_list['sql']['options'][] = array('type' => 'select', 'name' => 'type', 'text' => 'strSQLExportType', 'values' => array('INSERT' => 'INSERT', 'UPDATE' => 'UPDATE', 'REPLACE' => 'REPLACE')); $plugin_list['sql']['options'][] = array('type' => 'egroup'); }} else {/** * Avoids undefined variables, use NULL so isset() returns false */if (! isset($sql_backquotes)) { $sql_backquotes = null;}/** * Outputs comment * * @param string Text of comment * * @return string The formatted comment */function PMA_exportComment($text = ''){ if ($GLOBALS['sql_include_comments']) { // see http://dev.mysql.com/doc/refman/5.0/en/ansi-diff-comments.html return '--' . (empty($text) ? '' : ' ') . $text . $GLOBALS['crlf']; } else { return ''; }}/** * Outputs export footer * * @return bool Whether it suceeded * * @access public */function PMA_exportFooter(){ global $crlf; global $mysql_charset_map; $foot = ''; if (isset($GLOBALS['sql_disable_fk'])) { $foot .= $crlf . 'SET FOREIGN_KEY_CHECKS=1;' . $crlf; } if (isset($GLOBALS['sql_use_transaction'])) { $foot .= $crlf . 'COMMIT;' . $crlf; } // restore connection settings // (not set if $cfg['AllowAnywhereRecoding'] is false) $charset_of_file = isset($GLOBALS['charset_of_file']) ? $GLOBALS['charset_of_file'] : ''; if (!empty($GLOBALS['asfile']) && isset($mysql_charset_map[$charset_of_file])) { $foot .= $crlf . '/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;' . $crlf . '/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;' . $crlf . '/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;' . $crlf; } return PMA_exportOutputHandler($foot);}/** * Outputs export header * * @return bool Whether it suceeded * * @access public */function PMA_exportHeader(){ global $crlf; global $cfg; global $mysql_charset_map; if (isset($GLOBALS['sql_compatibility'])) { $tmp_compat = $GLOBALS['sql_compatibility']; if ($tmp_compat == 'NONE') { $tmp_compat = ''; } PMA_DBI_try_query('SET SQL_MODE="' . $tmp_compat . '"'); unset($tmp_compat); } $head = PMA_exportComment('phpMyAdmin SQL Dump') . PMA_exportComment('version ' . PMA_VERSION) . PMA_exportComment('http://www.phpmyadmin.net') . PMA_exportComment(); $head .= empty($cfg['Server']['port']) ? PMA_exportComment($GLOBALS['strHost'] . ': ' . $cfg['Server']['host']) : PMA_exportComment($GLOBALS['strHost'] . ': ' . $cfg['Server']['host'] . ':' . $cfg['Server']['port']); $head .= PMA_exportComment($GLOBALS['strGenTime'] . ': ' . PMA_localisedDate()) . PMA_exportComment($GLOBALS['strServerVersion'] . ': ' . substr(PMA_MYSQL_INT_VERSION, 0, 1) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 1, 2) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 3)) . PMA_exportComment($GLOBALS['strPHPVersion'] . ': ' . phpversion()); if (isset($GLOBALS['sql_header_comment']) && !empty($GLOBALS['sql_header_comment'])) { // '\n' is not a newline (like "\n" would be), it's the characters // backslash and n, as explained on the export interface $lines = explode('\n', $GLOBALS['sql_header_comment']); $head .= PMA_exportComment(); foreach($lines as $one_line) { $head .= PMA_exportComment($one_line); } $head .= PMA_exportComment(); } if (isset($GLOBALS['sql_disable_fk'])) { $head .= $crlf . 'SET FOREIGN_KEY_CHECKS=0;' . $crlf; } /* We want exported AUTO_INCREMENT fields to have still same value, do this only for recent MySQL exports */ if (!isset($GLOBALS['sql_compatibility']) || $GLOBALS['sql_compatibility'] == 'NONE') { $head .= $crlf . 'SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";' . $crlf; } if (isset($GLOBALS['sql_use_transaction'])) { $head .= $crlf .'SET AUTOCOMMIT=0;' . $crlf . 'START TRANSACTION;' . $crlf; } $head .= $crlf; if (! empty($GLOBALS['asfile'])) { // we are saving as file, therefore we provide charset information // so that a utility like the mysql client can interpret // the file correctly if (isset($GLOBALS['charset_of_file']) && isset($mysql_charset_map[$GLOBALS['charset_of_file']])) { // $cfg['AllowAnywhereRecoding'] was true so we got a charset from // the export dialog $set_names = $mysql_charset_map[$GLOBALS['charset_of_file']]; } else { // by default we use the connection charset $set_names = $mysql_charset_map[$GLOBALS['charset']]; } $head .= $crlf . '/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;' . $crlf . '/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;' . $crlf . '/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;' . $crlf . '/*!40101 SET NAMES ' . $set_names . ' */;' . $crlf . $crlf; } return PMA_exportOutputHandler($head);}/** * Outputs CREATE DATABASE database * * @param string Database name * * @return bool Whether it suceeded * * @access public */function PMA_exportDBCreate($db){ global $crlf; if (isset($GLOBALS['sql_drop_database'])) { if (!PMA_exportOutputHandler('DROP DATABASE ' . (isset($GLOBALS['sql_backquotes']) ? PMA_backquote($db) : $db) . ';' . $crlf)) { return FALSE; } } $create_query = 'CREATE DATABASE ' . (isset($GLOBALS['sql_backquotes']) ? PMA_backquote($db) : $db); $collation = PMA_getDbCollation($db); if (strpos($collation, '_')) { $create_query .= ' DEFAULT CHARACTER SET ' . substr($collation, 0, strpos($collation, '_')) . ' COLLATE ' . $collation; } else { $create_query .= ' DEFAULT CHARACTER SET ' . $collation; } $create_query .= ';' . $crlf; if (!PMA_exportOutputHandler($create_query)) { return FALSE; } if (isset($GLOBALS['sql_backquotes']) && isset($GLOBALS['sql_compatibility']) && $GLOBALS['sql_compatibility'] == 'NONE') { return PMA_exportOutputHandler('USE ' . PMA_backquote($db) . ';' . $crlf); } return PMA_exportOutputHandler('USE ' . $db . ';' . $crlf);}/** * Outputs database header * * @param string Database name * * @return bool Whether it suceeded * * @access public */function PMA_exportDBHeader($db){ $head = PMA_exportComment() . PMA_exportComment($GLOBALS['strDatabase'] . ': ' . (isset($GLOBALS['sql_backquotes']) ? PMA_backquote($db) : '\'' . $db . '\'')) . PMA_exportComment(); return PMA_exportOutputHandler($head);}/** * Outputs database footer * * @param string Database name * * @return bool Whether it suceeded * * @access public */function PMA_exportDBFooter($db){ global $crlf; $result = TRUE; if (isset($GLOBALS['sql_constraints'])) { $result = PMA_exportOutputHandler($GLOBALS['sql_constraints']); unset($GLOBALS['sql_constraints']); } if (isset($GLOBALS['sql_structure']) && isset($GLOBALS['sql_procedure_function'])) { $text = ''; $delimiter = '$$'; $procedure_names = PMA_DBI_get_procedures_or_functions($db, 'PROCEDURE'); $function_names = PMA_DBI_get_procedures_or_functions($db, 'FUNCTION');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -