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

📄 sql.php

📁 mysql管理
💻 PHP
📖 第 1 页 / 共 2 页
字号:
    $schema_create .= $auto_increment;    PMA_DBI_free_result($result);    return $schema_create;} // end of the 'PMA_getTableDef()' function/** * Returns $table's comments, relations etc. * * @param   string   the database name * @param   string   the table name * @param   string   the end of line sequence * @param   boolean  whether to include relation comments * @param   boolean  whether to include column comments * @param   boolean  whether to include mime comments * * @return  string   resulting comments * * @access  public */function PMA_getTableComments($db, $table, $crlf, $do_relation = false, $do_comments = false, $do_mime = false){    global $cfgRelation;    global $use_backquotes;    global $sql_constraints;    $schema_create = '';    if ($do_comments && $cfgRelation['commwork']) {        if (!($comments_map = PMA_getComments($db, $table))) unset($comments_map);    }    // Check if we can use Relations (Mike Beck)    if ($do_relation && !empty($cfgRelation['relation'])) {        // Find which tables are related with the current one and write it in        // an array        $res_rel = PMA_getForeigners($db, $table);        if ($res_rel && count($res_rel) > 0) {            $have_rel = TRUE;        } else {            $have_rel = FALSE;        }    }    else {           $have_rel = FALSE;    } // end if    if ($do_mime && $cfgRelation['mimework']) {        if (!($mime_map = PMA_getMIME($db, $table, true))) unset($mime_map);    }    if (isset($comments_map) && count($comments_map) > 0) {        $schema_create .= $crlf . $GLOBALS['comment_marker'] . $crlf                       . $GLOBALS['comment_marker'] . $GLOBALS['strCommentsForTable']. ' ' . PMA_backquote($table, $use_backquotes) . ':' . $crlf;        foreach ($comments_map AS $comment_field => $comment) {            $schema_create .= $GLOBALS['comment_marker'] . '  ' . PMA_backquote($comment_field, $use_backquotes) . $crlf                            . $GLOBALS['comment_marker'] . '      ' . PMA_backquote($comment, $use_backquotes) . $crlf;        }        $schema_create .= $GLOBALS['comment_marker'] . $crlf;    }    if (isset($mime_map) && count($mime_map) > 0) {        $schema_create .= $crlf . $GLOBALS['comment_marker'] . $crlf                       . $GLOBALS['comment_marker'] . $GLOBALS['strMIMETypesForTable']. ' ' . PMA_backquote($table, $use_backquotes) . ':' . $crlf;        @reset($mime_map);        foreach ($mime_map AS $mime_field => $mime) {            $schema_create .= $GLOBALS['comment_marker'] . '  ' . PMA_backquote($mime_field, $use_backquotes) . $crlf                            . $GLOBALS['comment_marker'] . '      ' . PMA_backquote($mime['mimetype'], $use_backquotes) . $crlf;        }        $schema_create .= $GLOBALS['comment_marker'] . $crlf;    }    if ($have_rel) {        $schema_create .= $crlf . $GLOBALS['comment_marker'] . $crlf                       . $GLOBALS['comment_marker'] . $GLOBALS['strRelationsForTable']. ' ' . PMA_backquote($table, $use_backquotes) . ':' . $crlf;        foreach ($res_rel AS $rel_field => $rel) {            $schema_create .= $GLOBALS['comment_marker'] . '  ' . PMA_backquote($rel_field, $use_backquotes) . $crlf                            . $GLOBALS['comment_marker'] . '      ' . PMA_backquote($rel['foreign_table'], $use_backquotes)                            . ' -> ' . PMA_backquote($rel['foreign_field'], $use_backquotes) . $crlf;        }        $schema_create .= $GLOBALS['comment_marker'] . $crlf;    }    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 column comments * @param   boolean  whether to include mime comments * * @return  bool     Whether it suceeded * * @access  public */function PMA_exportStructure($db, $table, $crlf, $error_url, $relation = FALSE, $comments = FALSE, $mime = FALSE, $dates = FALSE) {    $formatted_table_name = (isset($GLOBALS['use_backquotes']))                          ? PMA_backquote($table)                          : '\'' . $table . '\'';    $dump = $crlf          .  $GLOBALS['comment_marker'] . '--------------------------------------------------------' . $crlf          .  $crlf . $GLOBALS['comment_marker'] . $crlf          .  $GLOBALS['comment_marker'] . $GLOBALS['strTableStructure'] . ' ' . $formatted_table_name . $crlf          .  $GLOBALS['comment_marker'] . $crlf          .  PMA_getTableDef($db, $table, $crlf, $error_url, $dates) . ';' . $crlf          .  PMA_getTableComments($db, $table, $crlf, $relation, $comments, $mime);    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 $use_backquotes;    global $rows_cnt;    global $current_row;    $formatted_table_name = (isset($GLOBALS['use_backquotes']))                          ? PMA_backquote($table)                          : '\'' . $table . '\'';    $head = $crlf          . $GLOBALS['comment_marker'] . $crlf          . $GLOBALS['comment_marker'] . $GLOBALS['strDumpingData'] . ' ' . $formatted_table_name . $crlf          . $GLOBALS['comment_marker'] . $crlf .$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_query($sql_query, NULL, PMA_DBI_QUERY_UNBUFFERED);    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'], $use_backquotes);            } else {                $field_set[$j] = PMA_backquote($fields_meta[$j]->name, $use_backquotes);            }        }        if (isset($GLOBALS['sql_type']) && $GLOBALS['sql_type'] == 'update') {            // update            $schema_insert  = 'UPDATE ';            if (isset($GLOBALS['sql_ignore']))                $schema_insert .= 'IGNORE ';            $schema_insert .= PMA_backquote($table, $use_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['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['showcolumns'])) {                $fields        = implode(', ', $field_set);                $schema_insert = $sql_command . $insert_delayed .' INTO ' . PMA_backquote($table, $use_backquotes)                               . ' (' . $fields . ') VALUES (';            } else {                $schema_insert = $sql_command . $insert_delayed .' INTO ' . PMA_backquote($table, $use_backquotes)                               . ' VALUES (';            }        }        $search       = array("\x00", "\x0a", "\x0d", "\x1a"); //\x08\\x09, not required        $replace      = array('\0', '\n', '\r', '\Z');        $current_row  = 0;        $separator    = isset($GLOBALS['extended_ins']) ? ',' : ';';        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                } elseif ($fields_meta[$j]->numeric && $fields_meta[$j]->type != 'timestamp') {                    $values[] = $row[$j];                // a binary field                // Note: with mysqli, under MySQL 4.1.3, we get the flag                // "binary" for those field types (I don't know why)                } else if (stristr($field_flags[$j], 'BINARY')                        && isset($GLOBALS['hexforbinary'])                        && $fields_meta[$j]->type != 'datetime'                        && $fields_meta[$j]->type != 'date'                        && $fields_meta[$j]->type != 'time'                        && $fields_meta[$j]->type != 'timestamp'                       ) {                    // 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]);                    }                // 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 ($i > 0) {                        $insert_line .= ', ';                    }                    $insert_line .= $field_set[$i] . ' = ' . $values[$i];                }                $insert_line .= ' WHERE ' . PMA_getUvaCondition($result, $fields_cnt, $fields_meta, $row);            } else {                // Extended inserts case                if (isset($GLOBALS['extended_ins'])) {                    if ($current_row == 1) {                        $insert_line  = $schema_insert . implode(', ', $values) . ')';                    } else {                        $insert_line  = '(' . implode(', ', $values) . ')';                    }                }                // 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 + -