relation.lib.php

来自「php绿色服务器,让大家试用greenamp」· PHP 代码 · 共 746 行 · 第 1/2 页

PHP
746
字号
 * * @access  public * * @author  Mike Beck <mikebeck@users.sourceforge.net> */function PMA_getDisplayField($db, $table) {    global $cfgRelation;    if (trim(@$cfgRelation['table_info']) == '') {        return FALSE;    }    $disp_query      = 'SELECT display_field FROM ' . PMA_backquote($cfgRelation['table_info']);    if (PMA_MYSQL_INT_VERSION >= 40100) {        list($conn_charset) = explode('_', $GLOBALS['collation_connection']);        $disp_query .= ' WHERE CONVERT(db_name    USING ' . $conn_charset . ') = \'' . PMA_sqlAddslashes($db) . '\''                     . ' AND   CONVERT(table_name USING ' . $conn_charset . ') = \'' . PMA_sqlAddslashes($table) . '\'';    } else {        $disp_query .= ' WHERE db_name    = \'' . PMA_sqlAddslashes($db) . '\''                     . ' AND   table_name = \'' . PMA_sqlAddslashes($table) . '\'';    }    $disp_res   = PMA_query_as_cu($disp_query);    $row        = ($disp_res ? PMA_DBI_fetch_assoc($disp_res) : '');    PMA_DBI_free_result($disp_res);    if (isset($row['display_field'])) {        return $row['display_field'];    } else {        return FALSE;    }} // end of the 'PMA_getDisplayField()' function/** * Gets the comments for all rows of a table * * @param   string   the name of the db to check for * @param   string   the name of the table to check for * * @return  array    [field_name] = comment * * @global  array    the list of relations settings * * @access  public * * @author  Mike Beck <mikebeck@users.sourceforge.net> */function PMA_getComments($db, $table = '') {    global $cfgRelation;    if (PMA_MYSQL_INT_VERSION >= 40100) {        list($conn_charset) = explode('_', $GLOBALS['collation_connection']);    }    if ($table != '') {        $com_qry      = 'SELECT column_name, ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($cfgRelation['column_info']);        if (PMA_MYSQL_INT_VERSION >= 40100) {            $com_qry .= ' WHERE CONVERT(db_name    USING ' . $conn_charset . ') = \'' . PMA_sqlAddslashes($db) . '\''                      . ' AND   CONVERT(table_name USING ' . $conn_charset . ') = \'' . PMA_sqlAddslashes($table) . '\'';        } else {            $com_qry .= ' WHERE db_name    = \'' . PMA_sqlAddslashes($db) . '\''                      . ' AND   table_name = \'' . PMA_sqlAddslashes($table) . '\'';        }        $com_rs   = PMA_query_as_cu($com_qry, TRUE);    } else {        $com_qry      = 'SELECT ' . PMA_backquote('comment') . ' FROM ' . PMA_backquote($cfgRelation['column_info']);        if (PMA_MYSQL_INT_VERSION >= 40100) {            $com_qry .= ' WHERE CONVERT(db_name     USING ' . $conn_charset . ') = \'' . PMA_sqlAddslashes($db) . '\''                      . ' AND   CONVERT(table_name  USING ' . $conn_charset . ') = \'\''                      . ' AND   CONVERT(column_name USING ' . $conn_charset . ') = \'(db_comment)\'';        } else {            $com_qry .= ' WHERE db_name     = \'' . PMA_sqlAddslashes($db) . '\''                      . ' AND   table_name  = \'\''                      . ' AND   column_name = \'(db_comment)\'';        }        $com_rs   = PMA_query_as_cu($com_qry, TRUE);    }    $i = 0;    while ($row = PMA_DBI_fetch_assoc($com_rs)) {        $i++;        $col           = ($table != '' ? $row['column_name'] : $i);        if (strlen($row['comment']) > 0) {            $comment[$col] = $row['comment'];        }    } // end while    PMA_DBI_free_result($com_rs);    unset($com_rs);    if (isset($comment) && is_array($comment)) {        return $comment;     } else {        return FALSE;     } } // end of the 'PMA_getComments()' function/*** Adds/removes slashes if required** @param   string  the string to slash** @return  string  the slashed string** @access  public*/function PMA_handleSlashes($val) {  return (get_magic_quotes_gpc() ? str_replace('\\"', '"', $val) : PMA_sqlAddslashes($val));} // end of the "PMA_handleSlashes()" function/*** Set a single comment to a certain value.** @param   string   the name of the db* @param   string   the name of the table* @param   string   the name of the column* @param   string   the value of the column* @param   string   (optional) if a column is renamed, this is the name of the former key which will get deleted** @return  boolean  true, if comment-query was made.** @global  array    the list of relations settings** @access  public*/function PMA_setComment($db, $table, $key, $value, $removekey = '') {    global $cfgRelation;    if (PMA_MYSQL_INT_VERSION >= 40100) {        list($conn_charset) = explode('_', $GLOBALS['collation_connection']);        $cols = array(            'db_name'     => 'CONVERT(db_name     USING ' . $conn_charset . ')',            'table_name'  => 'CONVERT(table_name  USING ' . $conn_charset . ')',            'column_name' => 'CONVERT(column_name USING ' . $conn_charset . ')'        );    } else {        $cols = array(            'db_name'     => 'db_name    ',            'table_name'  => 'table_name ',            'column_name' => 'column_name'        );    }    if ($removekey != '' AND $removekey != $key) {        $remove_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_info'])                      . ' WHERE ' . $cols['db_name']     . ' = \'' . PMA_sqlAddslashes($db) . '\''                      . ' AND   ' . $cols['table_name']  . ' = \'' . PMA_sqlAddslashes($table) . '\''                      . ' AND   ' . $cols['column_name'] . ' = \'' . PMA_sqlAddslashes($removekey) . '\'';        PMA_query_as_cu($remove_query);        unset($remove_query);    }    $test_qry = 'SELECT ' . PMA_backquote('comment') . ', mimetype, transformation, transformation_options FROM ' . PMA_backquote($cfgRelation['column_info'])              . ' WHERE ' . $cols['db_name']     . ' = \'' . PMA_sqlAddslashes($db) . '\''              . ' AND   ' . $cols['table_name']  . ' = \'' . PMA_sqlAddslashes($table) . '\''              . ' AND   ' . $cols['column_name'] . ' = \'' . PMA_sqlAddslashes($key) . '\'';    $test_rs   = PMA_query_as_cu($test_qry, TRUE, PMA_DBI_QUERY_STORE);    if ($test_rs && PMA_DBI_num_rows($test_rs) > 0) {        $row = PMA_DBI_fetch_assoc($test_rs);        PMA_DBI_free_result($test_rs);        if (strlen($value) > 0 || strlen($row['mimetype']) > 0 || strlen($row['transformation']) > 0 || strlen($row['transformation_options']) > 0) {            $upd_query = 'UPDATE ' . PMA_backquote($cfgRelation['column_info'])                       . ' SET ' . PMA_backquote('comment') . ' = \'' . PMA_sqlAddslashes($value) . '\''                       . ' WHERE ' . $cols['db_name']     . ' = \'' . PMA_sqlAddslashes($db) . '\''                       . ' AND   ' . $cols['table_name']  . ' = \'' . PMA_sqlAddslashes($table) . '\''                       . ' AND   ' . $cols['column_name'] . ' = \'' . PMA_sqlAddSlashes($key) . '\'';        } else {            $upd_query = 'DELETE FROM ' . PMA_backquote($cfgRelation['column_info'])                       . ' WHERE ' . $cols['db_name']     . ' = \'' . PMA_sqlAddslashes($db) . '\''                       . ' AND   ' . $cols['table_name']  . ' = \'' . PMA_sqlAddslashes($table) . '\''                       . ' AND   ' . $cols['column_name'] . ' = \'' . PMA_sqlAddslashes($key) . '\'';        }    } else if (strlen($value) > 0) {        $upd_query = 'INSERT INTO ' . PMA_backquote($cfgRelation['column_info'])                   . ' (db_name, table_name, column_name, ' . PMA_backquote('comment') . ') '                   . ' VALUES('                   . '\'' . PMA_sqlAddslashes($db) . '\','                   . '\'' . PMA_sqlAddslashes($table) . '\','                   . '\'' . PMA_sqlAddslashes($key) . '\','                   . '\'' . PMA_sqlAddslashes($value) . '\')';    }    if (isset($upd_query)){        $upd_rs    = PMA_query_as_cu($upd_query);        unset($upd_query);        return true;    } else {        return false;    }} // end of 'PMA_setComment()' function/*** Set a SQL history entry** @param   string   the name of the db* @param   string   the name of the table* @param   string   the username* @param   string   the sql query** @return  boolean  true** @access  public*/function PMA_setHistory($db, $table, $username, $sqlquery) {    global $cfgRelation;    $hist_rs    = PMA_query_as_cu('INSERT INTO ' . PMA_backquote($cfgRelation['history']) . ' ('                . PMA_backquote('username') . ','                . PMA_backquote('db') . ','                . PMA_backquote('table') . ','                . PMA_backquote('timevalue') . ','                . PMA_backquote('sqlquery')                . ') VALUES ('                . '\'' . PMA_sqlAddslashes($username) . '\','                . '\'' . PMA_sqlAddslashes($db) . '\','                . '\'' . PMA_sqlAddslashes($table) . '\','                . 'NOW(),'                . '\'' . PMA_sqlAddslashes($sqlquery) . '\')');    return true;} // end of 'PMA_setHistory()' function/*** Gets a SQL history entry** @param   string   the username** @return  array    list of history items** @access  public*/function PMA_getHistory($username) {    global $cfgRelation;    $hist_query      = 'SELECT '                     . PMA_backquote('db') . ','                     . PMA_backquote('table') . ','                     . PMA_backquote('sqlquery')                     . ' FROM ' . PMA_backquote($cfgRelation['history'])                     . ' WHERE ';    if (PMA_MYSQL_INT_VERSION >= 40100) {        list($conn_charset) = explode('_', $GLOBALS['collation_connection']);        $hist_query .= 'CONVERT(username USING ' . $conn_charset . ')';        unset($conn_charset);    } else {        $hist_query .= 'username';    }    $hist_query     .= ' = \'' . PMA_sqlAddslashes($username) . '\' ORDER BY id DESC';    $hist_rs = PMA_query_as_cu($hist_query);    unset($hist_query);    $history = array();    while ($row = PMA_DBI_fetch_assoc($hist_rs)) {        $history[] = $row;    }    PMA_DBI_free_result($hist_rs);    return $history;} // end of 'PMA_getHistory()' function/*** Set a SQL history entry** @param   string   the name of the db* @param   string   the name of the table* @param   string   the username* @param   string   the sql query** @return  boolean  true** @access  public*/function PMA_purgeHistory($username) {    global $cfgRelation, $cfg;    $purge_query  = 'SELECT timevalue FROM ' . PMA_backquote($cfgRelation['history']) . ' WHERE ';    if (PMA_MYSQL_INT_VERSION >= 40100) {        list($conn_charset) = explode('_', $GLOBALS['collation_connection']);        $purge_query .= 'CONVERT(username USING ' . $conn_charset . ')';        unset($conn_charset);    } else {        $purge_query .= 'username';    }    $purge_query .= ' = \'' . PMA_sqlAddSlashes($username) . '\' ORDER BY timevalue DESC LIMIT ' . $cfg['QueryHistoryMax'] . ', 1';    $purge_rs = PMA_query_as_cu($purge_query);    $i = 0;    $row = PMA_DBI_fetch_row($purge_rs);    PMA_DBI_free_result($purge_rs);    if (is_array($row) && isset($row[0]) && $row[0] > 0) {        $maxtime = $row[0];        // quotes added around $maxtime to prevent a difficult to        // reproduce problem        $remove_rs = PMA_query_as_cu('DELETE FROM ' . PMA_backquote($cfgRelation['history']) . ' WHERE timevalue <= "' . $maxtime . '"');    }    return true;} // end of 'PMA_purgeHistory()' function/*** Outputs dropdown with values of foreign fields** @param   string   the query of the foreign keys* @param   string   the foreign field* @param   string   the foreign field to display* @param   string   the current data of the dropdown** @return  string   the <option value=""><option>s** @access  public*/function PMA_foreignDropdown($disp, $foreign_field, $foreign_display, $data, $max = 100) {    global $cfg;    $ret = '<option value=""></option>' . "\n";    $reloptions = array('content-id' => array(), 'id-content' => array());        foreach ($disp AS $disp_key => $relrow) {        $key   = $relrow[$foreign_field];        // if the display field has been defined for the foreign table        if ($foreign_display) {            if (PMA_strlen($relrow[$foreign_display]) <= $cfg['LimitChars']) {                $value  = htmlspecialchars($relrow[$foreign_display]);                $vtitle = '';            } else {                $vtitle = htmlspecialchars($relrow[$foreign_display]);                $value  = htmlspecialchars(substr($vtitle, 0, $cfg['LimitChars']) . '...');            }        } else {            $vtitle = $value = '';        } // end if ($foreign_display)        $reloption = '<option value="' . htmlspecialchars($key) . '"';        if ($vtitle != '') {            $reloption .= ' title="' . $vtitle . '"';        }        if ($key == $data) {           $reloption .= ' selected="selected"';        } // end if        $reloptions['id-content'][] = $reloption . '>' . $value . '&nbsp;-&nbsp;' . htmlspecialchars($key) .  '</option>' . "\n";        $reloptions['content-id'][] = $reloption . '>' . htmlspecialchars($key) .  '&nbsp;-&nbsp;' . $value . '</option>' . "\n";    } // end while    // the list of keys looks better if not sorted by description    if ($cfg['NaturalOrder']) {        natsort($reloptions['content-id']); }    else {        asort($reloptions['content-id']);    }    if ($max == -1 || count($reloptions['content-id']) < $max) {        $ret .= implode('', $reloptions['content-id']);        if (count($reloptions['content-id']) > 0) {            $ret .= '<option value=""></option>' . "\n";            $ret .= '<option value=""></option>' . "\n";        }    }    $ret .= implode('', $reloptions['id-content']);    return $ret;} // end of 'PMA_foreignDropdown()' function?>

⌨️ 快捷键说明

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