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

📄 sql.php

📁 一个用PHP编写的
💻 PHP
📖 第 1 页 / 共 3 页
字号:
                       . PMA_exportComment($GLOBALS['strMIMETypesForTable']. ' ' . PMA_backquote($table, $sql_backquotes) . ':');        @reset($mime_map);        foreach ($mime_map AS $mime_field => $mime) {            $schema_create .= PMA_exportComment('  ' . PMA_backquote($mime_field, $sql_backquotes))                            . PMA_exportComment('      ' . PMA_backquote($mime['mimetype'], $sql_backquotes));        }        $schema_create .= PMA_exportComment();    }    if ($have_rel) {        $schema_create .= $crlf                       . PMA_exportComment()                       . PMA_exportComment($GLOBALS['strRelationsForTable']. ' ' . PMA_backquote($table, $sql_backquotes) . ':');        foreach ($res_rel AS $rel_field => $rel) {            $schema_create .= PMA_exportComment('  ' . PMA_backquote($rel_field, $sql_backquotes))                            . PMA_exportComment('      ' . PMA_backquote($rel['foreign_table'], $sql_backquotes)                            . ' -> ' . PMA_backquote($rel['foreign_field'], $sql_backquotes));        }        $schema_create .= PMA_exportComment();    }    return $schema_create;} // end of the 'PMA_getTableComments()' function/** * Outputs table's structure * * @param   string   the database name * @param   string   the table name * @param   string   the end of line sequence * @param   string   the url to go back in case of error * @param   boolean  whether to include relation comments * @param   boolean  whether to include the pmadb-style column comments *                   as comments in the structure; this is deprecated *                   but the parameter is left here because export.php *                   calls PMA_exportStructure() also for other export *                   types which use this parameter * @param   boolean  whether to include mime comments * @param   string   'stand_in', 'create_table', 'create_view' * @param   string   'server', 'database', 'table' * * @return  bool     Whether it suceeded * * @access  public */function PMA_exportStructure($db, $table, $crlf, $error_url, $relation = FALSE, $comments = FALSE, $mime = FALSE, $dates = FALSE, $export_mode, $export_type){    $formatted_table_name = (isset($GLOBALS['sql_backquotes']))                          ? PMA_backquote($table)                          : '\'' . $table . '\'';    $dump = $crlf          . PMA_exportComment(str_repeat('-', 56))          . $crlf          . PMA_exportComment();    switch($export_mode) {        case 'create_table':            $dump .=  PMA_exportComment($GLOBALS['strTableStructure'] . ' ' . $formatted_table_name)                  . PMA_exportComment();            $dump .= PMA_getTableDef($db, $table, $crlf, $error_url, $dates);            $triggers = PMA_DBI_get_triggers($db, $table);            if ($triggers) {                $dump .=  $crlf                      . PMA_exportComment()                      . PMA_exportComment($GLOBALS['strTriggers'] . ' ' . $formatted_table_name)                      . PMA_exportComment();                $delimiter = '//';                foreach ($triggers as $trigger) {                    $dump .= $trigger['drop'] . ';' . $crlf;                    $dump .= 'DELIMITER ' . $delimiter . $crlf;                    $dump .= $trigger['create'];                    $dump .= 'DELIMITER ;' . $crlf;                }            }            break;        case 'create_view':            $dump .= PMA_exportComment($GLOBALS['strStructureForView'] . ' ' . $formatted_table_name)                  .  PMA_exportComment();            // delete the stand-in table previously created (if any)            if ($export_type != 'table') {                $dump .= 'DROP TABLE IF EXISTS ' . PMA_backquote($table) . ';' . $crlf;            }            $dump .= PMA_getTableDef($db, $table, $crlf, $error_url, $dates);            break;        case 'stand_in':            $dump .=  PMA_exportComment($GLOBALS['strStandInStructureForView'] . ' ' . $formatted_table_name)                  .  PMA_exportComment();            // export a stand-in definition to resolve view dependencies            $dump .= PMA_getTableDefStandIn($db, $table, $crlf);    } // end switch    $dump .= PMA_getTableComments($db, $table, $crlf, $relation, $mime);    // this one is built by PMA_getTableDef() to use in table copy/move    // but not in the case of export    unset($GLOBALS['sql_constraints_query']);    return PMA_exportOutputHandler($dump);}/** * Dispatches between the versions of 'getTableContent' to use depending * on the php version * * @param   string      the database name * @param   string      the table name * @param   string      the end of line sequence * @param   string      the url to go back in case of error * @param   string      SQL query for obtaining data * * @return  bool        Whether it suceeded * * @global  boolean  whether to use backquotes to allow the use of special *                   characters in database, table and fields names or not * @global  integer  the number of records * @global  integer  the current record position * * @access  public * * @see     PMA_getTableContentFast(), PMA_getTableContentOld() * * @author  staybyte */function PMA_exportData($db, $table, $crlf, $error_url, $sql_query){    global $sql_backquotes;    global $rows_cnt;    global $current_row;    $formatted_table_name = (isset($GLOBALS['sql_backquotes']))                          ? PMA_backquote($table)                          : '\'' . $table . '\'';    // Do not export data for a VIEW    // (For a VIEW, this is called only when exporting a single VIEW)    if (PMA_Table::isView($db, $table)) {        $head = $crlf          . PMA_exportComment()          . PMA_exportComment('VIEW ' . ' ' . $formatted_table_name)          . PMA_exportComment($GLOBALS['strData'] . ': ' . $GLOBALS['strNone'])          . PMA_exportComment()          . $crlf;        if (! PMA_exportOutputHandler($head)) {            return FALSE;        }        return true;    }    // it's not a VIEW    $head = $crlf          . PMA_exportComment()          . PMA_exportComment($GLOBALS['strDumpingData'] . ' ' . $formatted_table_name)          . PMA_exportComment()          . $crlf;    if (! PMA_exportOutputHandler($head)) {        return FALSE;    }    $buffer = '';    // analyze the query to get the true column names, not the aliases    // (this fixes an undefined index, also if Complete inserts    //  are used, we did not get the true column name in case of aliases)    $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($sql_query));    $result      = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);    // a possible error: the table has crashed    $tmp_error = PMA_DBI_getError();    if ($tmp_error) {        return PMA_exportOutputHandler(PMA_exportComment($GLOBALS['strInUse'] . ' (' . $tmp_error . ')'));    }    if ($result != FALSE) {        $fields_cnt     = PMA_DBI_num_fields($result);        // Get field information        $fields_meta    = PMA_DBI_get_fields_meta($result);        $field_flags    = array();        for ($j = 0; $j < $fields_cnt; $j++) {            $field_flags[$j] = PMA_DBI_field_flags($result, $j);        }        for ($j = 0; $j < $fields_cnt; $j++) {            if (isset($analyzed_sql[0]['select_expr'][$j]['column'])) {                $field_set[$j] = PMA_backquote($analyzed_sql[0]['select_expr'][$j]['column'], $sql_backquotes);            } else {                $field_set[$j] = PMA_backquote($fields_meta[$j]->name, $sql_backquotes);            }        }        if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'UPDATE') {            // update            $schema_insert  = 'UPDATE ';            if (isset($GLOBALS['sql_ignore'])) {                $schema_insert .= 'IGNORE ';            }            // avoid EOL blank            $schema_insert .= PMA_backquote($table, $sql_backquotes) . ' SET';        } else {            // insert or replace            if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'REPLACE') {                $sql_command    = 'REPLACE';            } else {                $sql_command    = 'INSERT';            }            // delayed inserts?            if (isset($GLOBALS['sql_delayed'])) {                $insert_delayed = ' DELAYED';            } else {                $insert_delayed = '';            }            // insert ignore?            if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'INSERT' && isset($GLOBALS['sql_ignore'])) {                $insert_delayed .= ' IGNORE';            }            // scheme for inserting fields            if (isset($GLOBALS['sql_columns'])) {                $fields        = implode(', ', $field_set);                $schema_insert = $sql_command . $insert_delayed .' INTO ' . PMA_backquote($table, $sql_backquotes)            // avoid EOL blank                               . ' (' . $fields . ') VALUES';            } else {                $schema_insert = $sql_command . $insert_delayed .' INTO ' . PMA_backquote($table, $sql_backquotes)                               . ' VALUES';            }        }        $search       = array("\x00", "\x0a", "\x0d", "\x1a"); //\x08\\x09, not required        $replace      = array('\0', '\n', '\r', '\Z');        $current_row  = 0;        $query_size   = 0;        if (isset($GLOBALS['sql_extended']) && (!isset($GLOBALS['sql_type']) || $GLOBALS['sql_type'] != 'UPDATE')) {            $separator    = ',';            $schema_insert .= $crlf;        } else {            $separator    = ';';        }        while ($row = PMA_DBI_fetch_row($result)) {            $current_row++;            for ($j = 0; $j < $fields_cnt; $j++) {                // NULL                if (!isset($row[$j]) || is_null($row[$j])) {                    $values[]     = 'NULL';                // a number                // timestamp is numeric on some MySQL 4.1, BLOBs are sometimes numeric                } elseif ($fields_meta[$j]->numeric && $fields_meta[$j]->type != 'timestamp'                        && ! $fields_meta[$j]->blob) {                    $values[] = $row[$j];                // a true BLOB                // - mysqldump only generates hex data when the --hex-blob                //   option is used, for fields having the binary attribute                //   no hex is generated                // - a TEXT field returns type blob but a real blob                //   returns also the 'binary' flag                } elseif (stristr($field_flags[$j], 'BINARY')                        && $fields_meta[$j]->blob                        && isset($GLOBALS['sql_hex_for_blob'])) {                    // empty blobs need to be different, but '0' is also empty :-(                    if (empty($row[$j]) && $row[$j] != '0') {                        $values[] = '\'\'';                    } else {                        $values[] = '0x' . bin2hex($row[$j]);                    }                // detection of 'bit' works only on mysqli extension                } elseif ($fields_meta[$j]->type == 'bit') {                    $values[] = "b'" . PMA_sqlAddslashes(PMA_printable_bit_value($row[$j], $fields_meta[$j]->length)) . "'";                // something else -> treat as a string                } else {                    $values[] = '\'' . str_replace($search, $replace, PMA_sqlAddslashes($row[$j])) . '\'';                } // end if            } // end for            // should we make update?            if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'UPDATE') {                $insert_line = $schema_insert;                for ($i = 0; $i < $fields_cnt; $i++) {                    if (0 == $i) {                        $insert_line .= ' ';                    }                    if ($i > 0) {                        // avoid EOL blank                        $insert_line .= ',';                    }                    $insert_line .= $field_set[$i] . ' = ' . $values[$i];                }                $insert_line .= ' WHERE ' . PMA_getUniqueCondition($result, $fields_cnt, $fields_meta, $row);            } else {                // Extended inserts case                if (isset($GLOBALS['sql_extended'])) {                    if ($current_row == 1) {                        $insert_line  = $schema_insert . '(' . implode(', ', $values) . ')';                    } else {                        $insert_line  = '(' . implode(', ', $values) . ')';                        if (isset($GLOBALS['sql_max_query_size']) && $GLOBALS['sql_max_query_size'] > 0 && $query_size + strlen($insert_line) > $GLOBALS['sql_max_query_size']) {                            if (!PMA_exportOutputHandler(';' . $crlf)) {                                return FALSE;                            }                            $query_size = 0;                            $current_row = 1;                            $insert_line = $schema_insert . $insert_line;                        }                    }                    $query_size += strlen($insert_line);                }                // Other inserts case                else {                    $insert_line      = $schema_insert . '(' . implode(', ', $values) . ')';                }            }            unset($values);            if (!PMA_exportOutputHandler(($current_row == 1 ? '' : $separator . $crlf) . $insert_line)) {                return FALSE;            }        } // end while        if ($current_row > 0) {            if (!PMA_exportOutputHandler(';' . $crlf)) {                return FALSE;            }        }    } // end if ($result != FALSE)    PMA_DBI_free_result($result);    return TRUE;} // end of the 'PMA_exportData()' function}?>

⌨️ 快捷键说明

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