本文整理汇总了PHP中PMA_Index类的典型用法代码示例。如果您正苦于以下问题:PHP PMA_Index类的具体用法?PHP PMA_Index怎么用?PHP PMA_Index使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PMA_Index类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: PMA_getHtmlForDisplayIndexes
/**
* Get HTML for display indexes
*
* @return string $html_output
*/
function PMA_getHtmlForDisplayIndexes()
{
$html_output = PMA_Util::getDivForSliderEffect('indexes', __('Indexes'));
$html_output .= PMA_Index::getView($GLOBALS['table'], $GLOBALS['db']);
$html_output .= '<fieldset class="tblFooters" style="text-align: left;">' . '<form action="tbl_indexes.php" method="post">';
$html_output .= PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']) . sprintf(__('Create an index on %s columns'), '<input type="text" size="2" name="added_fields" value="1" />');
$html_output .= '<input type="hidden" name="create_index" value="1" />' . '<input class="add_index ajax"' . ' type="submit" value="' . __('Go') . '" />';
$html_output .= '</form>' . '</fieldset>' . '</div>' . '</div>';
return $html_output;
}
示例2: PMA_getHtmlForDisplayIndexes
/**
* Get HTML for display indexes
*
* @return string $html_output
*/
function PMA_getHtmlForDisplayIndexes()
{
$html_output = '<div id="index_div" class="ajax';
if ($GLOBALS['cfg']['InitialSlidersState'] != 'disabled') {
$html_output .= ' print_ignore';
}
$html_output .= '" >';
$html_output .= PMA_Util::getDivForSliderEffect('indexes', __('Indexes'));
$html_output .= PMA_Index::getHtmlForIndexes($GLOBALS['table'], $GLOBALS['db']);
$html_output .= '<fieldset class="tblFooters print_ignore" style="text-align: ' . 'left;"><form action="tbl_indexes.php" method="post">';
$html_output .= PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
$html_output .= sprintf(__('Create an index on %s columns'), '<input type="number" name="added_fields" value="1" ' . 'min="1" required="required" />');
$html_output .= '<input type="hidden" name="create_index" value="1" />' . '<input class="add_index ajax"' . ' type="submit" value="' . __('Go') . '" />';
$html_output .= '</form>' . '</fieldset>' . '</div>' . '</div>';
return $html_output;
}
示例3: validateTableAndLoadFields
/**
* Validate whether the table exists.
*
* @return void
*/
protected function validateTableAndLoadFields()
{
$sql = 'DESCRIBE ' . PMA_Util::backquote($this->tableName);
$result = $GLOBALS['dbi']->tryQuery($sql, null, PMA_DatabaseInterface::QUERY_STORE);
if (!$result || !$GLOBALS['dbi']->numRows($result)) {
$this->showMissingTableError();
}
if ($this->showKeys) {
$indexes = PMA_Index::getFromTable($this->tableName, $this->db);
$all_columns = array();
foreach ($indexes as $index) {
$all_columns = array_merge($all_columns, array_flip(array_keys($index->getColumns())));
}
$this->fields = array_keys($all_columns);
} else {
while ($row = $GLOBALS['dbi']->fetchRow($result)) {
$this->fields[] = $row[0];
}
}
}
示例4: _getUnsortedSqlAndSortByKeyDropDown
/**
* Prepare unsorted sql query and sort by key drop down
*
* @param array $analyzed_sql the analyzed query
* @param string $sort_expression sort expression
*
* @return array two element array - $unsorted_sql_query, $drop_down_html
*
* @access private
*
* @see _getTableHeaders()
*/
private function _getUnsortedSqlAndSortByKeyDropDown($analyzed_sql, $sort_expression)
{
$drop_down_html = '';
// Just as fallback
$unsorted_sql_query = $this->__get('sql_query');
if (isset($analyzed_sql[0]['unsorted_query'])) {
$unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
}
// Handles the case of multiple clicks on a column's header
// which would add many spaces before "ORDER BY" in the
// generated query.
$unsorted_sql_query = trim($unsorted_sql_query);
// sorting by indexes, only if it makes sense (only one table ref)
if (isset($analyzed_sql) && isset($analyzed_sql[0]) && isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == self::QUERY_TYPE_SELECT && isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
// grab indexes data:
$indexes = PMA_Index::getFromTable($this->__get('table'), $this->__get('db'));
// do we have any index?
if ($indexes) {
$drop_down_html = $this->_getSortByKeyDropDown($indexes, $sort_expression, $unsorted_sql_query);
}
}
return array($unsorted_sql_query, $drop_down_html);
}
示例5: PMA_displayTableHeaders
/**
* Displays the headers of the results table
*
* @uses $_SESSION['tmp_user_values']['disp_direction']
* @uses $_SESSION['tmp_user_values']['repeat_cells']
* @uses $_SESSION['tmp_user_values']['max_rows']
* @uses $_SESSION['tmp_user_values']['display_text']
* @uses $_SESSION['tmp_user_values']['display_binary']
* @uses $_SESSION['tmp_user_values']['display_binary_as_hex']
* @param array which elements to display
* @param array the list of fields properties
* @param integer the total number of fields returned by the SQL query
* @param array the analyzed query
*
* @return boolean $clause_is_unique
*
* @global string $db the database name
* @global string $table the table name
* @global string $goto the URL to go back in case of errors
* @global string $sql_query the SQL query
* @global integer $num_rows the total number of rows returned by the
* SQL query
* @global array $vertical_display informations used with vertical display
* mode
*
* @access private
*
* @see PMA_displayTable()
*/
function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '', $sort_expression, $sort_expression_nodirection, $sort_direction)
{
global $db, $table, $goto;
global $sql_query, $num_rows;
global $vertical_display, $highlight_columns;
if ($analyzed_sql == '') {
$analyzed_sql = array();
}
// can the result be sorted?
if ($is_display['sort_lnk'] == '1') {
// Just as fallback
$unsorted_sql_query = $sql_query;
if (isset($analyzed_sql[0]['unsorted_query'])) {
$unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
}
// Handles the case of multiple clicks on a column's header
// which would add many spaces before "ORDER BY" in the
// generated query.
$unsorted_sql_query = trim($unsorted_sql_query);
// sorting by indexes, only if it makes sense (only one table ref)
if (isset($analyzed_sql) && isset($analyzed_sql[0]) && isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' && isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
// grab indexes data:
$indexes = PMA_Index::getFromTable($table, $db);
// do we have any index?
if ($indexes) {
if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
$span = $fields_cnt;
if ($is_display['edit_lnk'] != 'nn') {
$span++;
}
if ($is_display['del_lnk'] != 'nn') {
$span++;
}
if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
$span++;
}
} else {
$span = $num_rows + floor($num_rows / $_SESSION['tmp_user_values']['repeat_cells']) + 1;
}
echo '<form action="sql.php" method="post">' . "\n";
echo PMA_generate_common_hidden_inputs($db, $table);
echo $GLOBALS['strSortByKey'] . ': <select name="sql_query" onchange="this.form.submit();">' . "\n";
$used_index = false;
$local_order = isset($sort_expression) ? $sort_expression : '';
foreach ($indexes as $index) {
$asc_sort = '`' . implode('` ASC, `', array_keys($index->getColumns())) . '` ASC';
$desc_sort = '`' . implode('` DESC, `', array_keys($index->getColumns())) . '` DESC';
$used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
echo '<option value="' . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort) . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '') . '>' . htmlspecialchars($index->getName()) . ' (' . $GLOBALS['strAscending'] . ')</option>';
echo '<option value="' . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort) . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '') . '>' . htmlspecialchars($index->getName()) . ' (' . $GLOBALS['strDescending'] . ')</option>';
}
echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . $GLOBALS['strNone'] . '</option>';
echo '</select>' . "\n";
echo '<noscript><input type="submit" value="' . $GLOBALS['strGo'] . '" /></noscript>';
echo '</form>' . "\n";
}
}
}
$vertical_display['emptypre'] = 0;
$vertical_display['emptyafter'] = 0;
$vertical_display['textbtn'] = '';
// Display options (if we are not in print view)
if (!(isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1')) {
echo '<form method="post" action="sql.php" name="displayOptionsForm" id="displayOptionsForm">';
$url_params = array('db' => $db, 'table' => $table, 'sql_query' => $sql_query, 'goto' => $goto, 'display_options_form' => 1);
echo PMA_generate_common_hidden_inputs($url_params);
echo '<br />';
PMA_generate_slider_effect('displayoptions', $GLOBALS['strOptions']);
echo '<fieldset>';
echo '<div class="formelement">';
$choices = array('P' => $GLOBALS['strPartialText'], 'F' => $GLOBALS['strFullText']);
//.........这里部分代码省略.........
示例6: _getUnsortedSqlAndSortByKeyDropDown
/**
* Prepare unsorted sql query and sort by key drop down
*
* @param array $analyzed_sql_results analyzed sql results
* @param string $sort_expression sort expression
*
* @return array two element array - $unsorted_sql_query, $drop_down_html
*
* @access private
*
* @see _getTableHeaders()
*/
private function _getUnsortedSqlAndSortByKeyDropDown($analyzed_sql_results, $sort_expression)
{
$drop_down_html = '';
$unsorted_sql_query = SqlParser\Utils\Query::replaceClause($analyzed_sql_results['statement'], $analyzed_sql_results['parser']->list, 'ORDER BY', '');
// Data is sorted by indexes only if it there is only one table.
if ($this->_isSelect($analyzed_sql_results)) {
// grab indexes data:
$indexes = PMA_Index::getFromTable($this->__get('table'), $this->__get('db'));
// do we have any index?
if (!empty($indexes)) {
$drop_down_html = $this->_getSortByKeyDropDown($indexes, $sort_expression, $unsorted_sql_query);
}
}
return array($unsorted_sql_query, $drop_down_html);
}
示例7: foreach
*/
$columns = $GLOBALS['dbi']->getColumns($GLOBALS['db'], $GLOBALS['table']);
/**
* Displays the page
*/
$response->addHTML('<div id="boxContainer" data-box-width="300">');
/**
* Order the table
*/
$hideOrderTable = false;
// `ALTER TABLE ORDER BY` does not make sense for InnoDB tables that contain
// a user-defined clustered index (PRIMARY KEY or NOT NULL UNIQUE index).
// InnoDB always orders table rows according to such an index if one is present.
if ($tbl_storage_engine == 'INNODB') {
include_once 'libraries/Index.class.php';
$indexes = PMA_Index::getFromTable($GLOBALS['table'], $GLOBALS['db']);
foreach ($indexes as $name => $idx) {
if ($name == 'PRIMARY') {
$hideOrderTable = true;
break;
} elseif (!$idx->getNonUnique()) {
$notNull = true;
foreach ($idx->getColumns() as $column) {
if ($column->getNull()) {
$notNull = false;
break;
}
}
if ($notNull) {
$hideOrderTable = true;
break;
示例8: PMA_getColumnsWithUniqueIndex
/**
* Get columns with unique index
*
* @param string $db database name
* @param string $table tablename
*
* @return array $columns_with_unique_index An array of columns with unique index,
* with $column name as the array key
*/
function PMA_getColumnsWithUniqueIndex($db, $table)
{
$columns_with_unique_index = array();
foreach (PMA_Index::getFromTable($table, $db) as $index) {
if ($index->isUnique() && $index->getChoice() == 'UNIQUE') {
$columns = $index->getColumns();
foreach ($columns as $column_name => $dummy) {
$columns_with_unique_index[$column_name] = 1;
}
}
}
return $columns_with_unique_index;
}
示例9: findDuplicates
/**
* Function to check over array of indexes and look for common problems
*
* @uses is_string()
* @uses is_array()
* @uses count()
* @uses array_pop()
* @uses reset()
* @uses current()
* @access public
* @param string name of table
* @return string Output HTML
*/
public static function findDuplicates($table, $schema)
{
$indexes = PMA_Index::getFromTable($table, $schema);
$output = '';
// count($indexes) < 2:
// there is no need to check if there less than two indexes
if (count($indexes) < 2) {
return $output;
}
// remove last index from stack and ...
while ($while_index = array_pop($indexes)) {
// ... compare with every remaining index in stack
foreach ($indexes as $each_index) {
if ($each_index->getCompareData() !== $while_index->getCompareData()) {
continue;
}
// did not find any difference
// so it makes no sense to have this two equal indexes
$message = PMA_Message::error(__('The indexes %1$s and %2$s seem to be equal and one of them could possibly be removed.'));
$message->addParam($each_index->getName());
$message->addParam($while_index->getName());
$output .= $message->getDisplay();
// there is no need to check any further indexes if we have already
// found that this one has a duplicate
continue 2;
}
}
return $output;
}
示例10: PMA_getReservedWordColumnNameMessages
$url_params['goto'] = 'tbl_structure.php';
$url_params['back'] = 'tbl_structure.php';
// Check column names for MySQL reserved words
$reserved_word_column_messages = PMA_getReservedWordColumnNameMessages($db, $table);
$response->addHTML($reserved_word_column_messages);
/**
* Prepares the table structure display
*/
/**
* Gets tables informations
*/
require_once 'libraries/tbl_info.inc.php';
require_once 'libraries/Index.class.php';
// 2. Gets table keys and retains them
// @todo should be: $server->db($db)->table($table)->primary()
$primary = PMA_Index::getPrimary($table, $db);
$columns_with_unique_index = PMA_getColumnsWithUniqueIndex($db, $table);
// 3. Get fields
$fields = (array) $GLOBALS['dbi']->getColumns($db, $table, null, true);
// Get more complete field information
// For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options
// but later, if the analyser returns more information, it
// could be executed for any MySQL version and replace
// the info given by SHOW FULL COLUMNS FROM.
//
// We also need this to correctly learn if a TIMESTAMP is NOT NULL, since
// SHOW FULL COLUMNS or INFORMATION_SCHEMA incorrectly says NULL
// and SHOW CREATE TABLE says NOT NULL (tested
// in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
$show_create_table = $GLOBALS['dbi']->fetchValue('SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table), 0, 1);
$analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table));
示例11: testColumns
/**
* Test for PMA_Index_Column
*
* @return void
*/
public function testColumns()
{
$index = new PMA_Index();
$index->addColumns($this->_params['columns']);
$index_columns = $index->getColumns();
$index_column = $index_columns['column1'];
$this->assertEquals('column1', $index_column->getName());
$this->assertEquals('index1', $index_column->getSeqInIndex());
$this->assertEquals('Collation1', $index_column->getCollation());
$this->assertEquals('Cardinality1', $index_column->getCardinality());
}
示例12: PMA_resultSetContainsUniqueKey
/**
* Verify whether the result set contains all the columns
* of at least one unique key
*
* @param string $db database name
* @param string $table table name
* @param string $fields_meta meta fields
*
* @return boolean whether the result set contains a unique key
*/
function PMA_resultSetContainsUniqueKey($db, $table, $fields_meta)
{
$resultSetColumnNames = array();
foreach ($fields_meta as $oneMeta) {
$resultSetColumnNames[] = $oneMeta->name;
}
foreach (PMA_Index::getFromTable($table, $db) as $index) {
if ($index->isUnique()) {
$indexColumns = $index->getColumns();
$numberFound = 0;
foreach ($indexColumns as $indexColumnName => $dummy) {
if (in_array($indexColumnName, $resultSetColumnNames)) {
$numberFound++;
}
}
if ($numberFound == count($indexColumns)) {
return true;
}
}
}
return false;
}
示例13: PMA_buildIndexStatements
/**
* Create relevant index statements
*
* @param array $index an array of index columns
* @param string $index_choice index choice that which represents
* the index type of $indexed_fields
* @param boolean $is_create_tbl true if requirement is to get the statement
* for table creation
*
* @return array an array of sql statements for indexes
*/
function PMA_buildIndexStatements($index, $index_choice, $is_create_tbl = true)
{
$statement = array();
if (!count($index)) {
return $statement;
}
$sql_query = PMA_getStatementPrefix($is_create_tbl) . ' ' . $index_choice;
if (!empty($index['Key_name']) && $index['Key_name'] != 'PRIMARY') {
$sql_query .= ' ' . PMA_Util::backquote($index['Key_name']);
}
$index_fields = array();
foreach ($index['columns'] as $key => $column) {
$index_fields[$key] = PMA_Util::backquote($_REQUEST['field_name'][$column['col_index']]);
if ($column['size']) {
$index_fields[$key] .= '(' . $column['size'] . ')';
}
}
// end while
$sql_query .= ' (' . implode(', ', $index_fields) . ')';
$keyBlockSizes = $index['Key_block_size'];
if (!empty($keyBlockSizes)) {
$sql_query .= " KEY_BLOCK_SIZE = " . PMA_Util::sqlAddSlashes($keyBlockSizes);
}
// specifying index type is allowed only for primary, unique and index only
$type = $index['Index_type'];
if ($index['Index_choice'] != 'SPATIAL' && $index['Index_choice'] != 'FULLTEXT' && in_array($type, PMA_Index::getIndexTypes())) {
$sql_query .= ' USING ' . $type;
}
$parser = $index['Parser'];
if ($index['Index_choice'] == 'FULLTEXT' && !empty($parser)) {
$sql_query .= " WITH PARSER " . PMA_Util::sqlAddSlashes($parser);
}
$comment = $index['Index_comment'];
if (!empty($comment)) {
$sql_query .= " COMMENT '" . PMA_Util::sqlAddSlashes($comment) . "'";
}
$statement[] = $sql_query;
return $statement;
}
示例14: str_replace
$fields[$row['Field']] = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')';
} else {
$fields[$row['Field']] = $row['Type'];
}
}
// end while
// Prepares the form values
if (isset($_REQUEST['index'])) {
if (is_array($_REQUEST['index'])) {
// coming already from form
$index = new PMA_Index($_REQUEST['index']);
} else {
$index = PMA_Index::singleton($db, $table, $_REQUEST['index']);
}
} else {
$index = new PMA_Index();
}
/**
* Process the data from the edit/create index form,
* run the query to build the new index
* and moves back to "tbl_sql.php"
*/
if (isset($_REQUEST['do_save_data'])) {
$error = false;
// $sql_query is the one displayed in the query box
$sql_query = 'ALTER TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table);
// Drops the old index
if (!empty($_REQUEST['old_index'])) {
if ($_REQUEST['old_index'] == 'PRIMARY') {
$sql_query .= ' DROP PRIMARY KEY,';
} else {
示例15: PMA_findPartialDependencies
/**
* find all the possible partial dependencies based on data in the table.
*
* @param string $table current table
* @param string $db current database
*
* @return HTML containing the list of all the possible partial dependencies
*/
function PMA_findPartialDependencies($table, $db)
{
$dependencyList = array();
$GLOBALS['dbi']->selectDb($db, $GLOBALS['userlink']);
$columns = (array) $GLOBALS['dbi']->getColumnNames($db, $table, $GLOBALS['userlink']);
$columns = (array) PMA_Util::backquote($columns);
$totalRowsRes = $GLOBALS['dbi']->fetchResult('SELECT COUNT(*) FROM (SELECT * FROM ' . PMA_Util::backquote($table) . ' LIMIT 500) as dt;');
$totalRows = $totalRowsRes[0];
$primary = PMA_Index::getPrimary($table, $db);
$primarycols = $primary->getColumns();
$pk = array();
foreach ($primarycols as $col) {
$pk[] = PMA_Util::backquote($col->getName());
}
$partialKeys = PMA_getAllCombinationPartialKeys($pk);
$distinctValCount = PMA_findDistinctValuesCount(array_unique(array_merge($columns, $partialKeys)), $table);
foreach ($columns as $column) {
if (!in_array($column, $pk)) {
foreach ($partialKeys as $partialKey) {
if ($partialKey && PMA_checkPartialDependency($partialKey, $column, $table, $distinctValCount[$partialKey], $distinctValCount[$column], $totalRows)) {
$dependencyList[$partialKey][] = $column;
}
}
}
}
$html = __('This list is based on a subset of the table\'s data ' . 'and is not necessarily accurate. ') . '<div class="dependencies_box">';
foreach ($dependencyList as $dependon => $colList) {
$html .= '<span class="displayblock">' . '<input type="button" class="pickPd" value="' . __('Pick') . '"/>' . '<span class="determinants">' . htmlspecialchars(str_replace('`', '', $dependon)) . '</span> -> ' . '<span class="dependents">' . htmlspecialchars(str_replace('`', '', implode(', ', $colList))) . '</span>' . '</span>';
}
if (empty($dependencyList)) {
$html .= '<p class="displayblock desc">' . __('No partial dependencies found!') . '</p>';
}
$html .= '</div>';
return $html;
}