本文整理汇总了PHP中PMA_Table::countRecords方法的典型用法代码示例。如果您正苦于以下问题:PHP PMA_Table::countRecords方法的具体用法?PHP PMA_Table::countRecords怎么用?PHP PMA_Table::countRecords使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PMA_Table
的用法示例。
在下文中一共展示了PMA_Table::countRecords方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: PMA_getTableList
/**
* returns array with tables of given db with extended information and grouped
*
* @uses $cfg['LeftFrameTableSeparator']
* @uses $cfg['LeftFrameTableLevel']
* @uses $cfg['ShowTooltipAliasTB']
* @uses $cfg['NaturalOrder']
* @uses PMA_backquote()
* @uses count()
* @uses array_merge
* @uses uksort()
* @uses strstr()
* @uses explode()
* @param string $db name of db
* @param string $tables name of tables
* @param integer $limit_offset list offset
* @param integer $limit_count max tables to return
* return array (recursive) grouped table list
*/
function PMA_getTableList($db, $tables = null, $limit_offset = 0, $limit_count = false)
{
$sep = $GLOBALS['cfg']['LeftFrameTableSeparator'];
if (null === $tables) {
$tables = PMA_DBI_get_tables_full($db, false, false, null, $limit_offset, $limit_count);
if ($GLOBALS['cfg']['NaturalOrder']) {
uksort($tables, 'strnatcasecmp');
}
}
if (count($tables) < 1) {
return $tables;
}
$default = array('Name' => '', 'Rows' => 0, 'Comment' => '', 'disp_name' => '');
$table_groups = array();
// for blobstreaming - list of blobstreaming tables - rajk
// load PMA configuration
$PMA_Config = $_SESSION['PMA_Config'];
// if PMA configuration exists
if (!empty($PMA_Config)) {
$session_bs_tables = $_SESSION['PMA_Config']->get('BLOBSTREAMING_TABLES');
}
foreach ($tables as $table_name => $table) {
// if BS tables exist
if (isset($session_bs_tables)) {
// compare table name to tables in list of blobstreaming tables
foreach ($session_bs_tables as $table_key => $table_val) {
// if table is in list, skip outer foreach loop
if ($table_name == $table_key) {
continue 2;
}
}
}
// check for correct row count
if (null === $table['Rows']) {
// Do not check exact row count here,
// if row count is invalid possibly the table is defect
// and this would break left frame;
// but we can check row count if this is a view or the
// information_schema database
// since PMA_Table::countRecords() returns a limited row count
// in this case.
// set this because PMA_Table::countRecords() can use it
$tbl_is_view = PMA_Table::isView($db, $table['Name']);
if ($tbl_is_view || 'information_schema' == $db) {
$table['Rows'] = PMA_Table::countRecords($db, $table['Name'], $return = true);
}
}
// in $group we save the reference to the place in $table_groups
// where to store the table info
if ($GLOBALS['cfg']['LeftFrameDBTree'] && $sep && strstr($table_name, $sep)) {
$parts = explode($sep, $table_name);
$group =& $table_groups;
$i = 0;
$group_name_full = '';
while ($i < count($parts) - 1 && $i < $GLOBALS['cfg']['LeftFrameTableLevel']) {
$group_name = $parts[$i] . $sep;
$group_name_full .= $group_name;
if (!isset($group[$group_name])) {
$group[$group_name] = array();
$group[$group_name]['is' . $sep . 'group'] = true;
$group[$group_name]['tab' . $sep . 'count'] = 1;
$group[$group_name]['tab' . $sep . 'group'] = $group_name_full;
} elseif (!isset($group[$group_name]['is' . $sep . 'group'])) {
$table = $group[$group_name];
$group[$group_name] = array();
$group[$group_name][$group_name] = $table;
unset($table);
$group[$group_name]['is' . $sep . 'group'] = true;
$group[$group_name]['tab' . $sep . 'count'] = 1;
$group[$group_name]['tab' . $sep . 'group'] = $group_name_full;
} else {
$group[$group_name]['tab' . $sep . 'count']++;
}
$group =& $group[$group_name];
$i++;
}
} else {
if (!isset($table_groups[$table_name])) {
$table_groups[$table_name] = array();
}
$group =& $table_groups;
//.........这里部分代码省略.........
示例2: PMA_calculatePosForLastPage
/**
* Function to calculate new pos if pos is higher than number of rows
* of displayed table
*
* @param String $db Database name
* @param String $table Table name
* @param Int|null $pos Initial position
*
* @return Int Number of pos to display last page
*/
function PMA_calculatePosForLastPage($db, $table, $pos)
{
if (null === $pos) {
$pos = $_SESSION['tmpval']['pos'];
}
$unlim_num_rows = PMA_Table::countRecords($db, $table, true);
//If position is higher than number of rows
if ($unlim_num_rows <= $pos && 0 != $pos) {
$pos = PMA_getStartPosToDisplayRow($unlim_num_rows);
}
return $pos;
}
示例3: _setDisplayParts
//.........这里部分代码省略.........
$displayParts['nav_bar'] = (string) '0';
$displayParts['ins_row'] = (string) '0';
$displayParts['bkm_form'] = (string) '1';
if ($this->__get('is_maint')) {
$displayParts['text_btn'] = (string) '1';
} else {
$displayParts['text_btn'] = (string) '0';
}
$displayParts['pview_lnk'] = (string) '1';
} elseif ($this->__get('is_show')) {
// 2.2 Statement is a "SHOW..."
/**
* 2.2.1
* @todo defines edit/delete links depending on show statement
*/
preg_match('@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?' . 'PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS' . ')@i', $this->__get('sql_query'), $which);
$bIsProcessList = isset($which[1]);
if ($bIsProcessList) {
$str = ' ' . strtoupper($which[1]);
$bIsProcessList = $bIsProcessList && strpos($str, 'PROCESSLIST') > 0;
}
if ($bIsProcessList) {
// no edit link
$displayParts['edit_lnk'] = self::NO_EDIT_OR_DELETE;
// "kill process" type edit link
$displayParts['del_lnk'] = self::KILL_PROCESS;
} else {
// Default case -> no links
// no edit link
$displayParts['edit_lnk'] = self::NO_EDIT_OR_DELETE;
// no delete link
$displayParts['del_lnk'] = self::NO_EDIT_OR_DELETE;
}
unset($bIsProcessList);
// 2.2.2 Other settings
$displayParts['sort_lnk'] = (string) '0';
$displayParts['nav_bar'] = (string) '0';
$displayParts['ins_row'] = (string) '0';
$displayParts['bkm_form'] = (string) '1';
$displayParts['text_btn'] = (string) '1';
$displayParts['pview_lnk'] = (string) '1';
} else {
// 2.3 Other statements (ie "SELECT" ones) -> updates
// $displayParts['edit_lnk'], $displayParts['del_lnk'] and
// $displayParts['text_btn'] (keeps other default values)
$prev_table = '';
$displayParts['text_btn'] = (string) '1';
for ($i = 0; $i < $this->__get('fields_cnt'); $i++) {
$is_link = $displayParts['edit_lnk'] != self::NO_EDIT_OR_DELETE || $displayParts['del_lnk'] != self::NO_EDIT_OR_DELETE || $displayParts['sort_lnk'] != '0' || $displayParts['ins_row'] != '0';
// 2.3.2 Displays edit/delete/sort/insert links?
if ($is_link && $prev_table != '' && $fields_meta[$i]->table != '' && $fields_meta[$i]->table != $prev_table) {
// don't display links
$displayParts['edit_lnk'] = self::NO_EDIT_OR_DELETE;
$displayParts['del_lnk'] = self::NO_EDIT_OR_DELETE;
/**
* @todo May be problematic with same field names
* in two joined table.
*/
// $displayParts['sort_lnk'] = (string) '0';
$displayParts['ins_row'] = (string) '0';
if ($displayParts['text_btn'] == '1') {
break;
}
}
// end if (2.3.2)
// 2.3.3 Always display print view link
$displayParts['pview_lnk'] = (string) '1';
if ($fields_meta[$i]->table != '') {
$prev_table = $fields_meta[$i]->table;
}
}
// end for
}
// end if..elseif...else (2.1 -> 2.3)
// 3. Gets the total number of rows if it is unknown
if (isset($unlim_num_rows) && $unlim_num_rows != '') {
$the_total = $unlim_num_rows;
} elseif (($displayParts['nav_bar'] == '1' || $displayParts['sort_lnk'] == '1') && (mb_strlen($db) && !empty($table))) {
$the_total = PMA_Table::countRecords($db, $table);
}
// if for COUNT query, number of rows returned more than 1 (may be being used GROUP BY)
if ($this->__get('is_count') && isset($num_rows) && $num_rows > 1) {
$displayParts['nav_bar'] = (string) '1';
$displayParts['sort_lnk'] = (string) '1';
}
// 4. If navigation bar or sorting fields names URLs should be
// displayed but there is only one row, change these settings to
// false
if ($displayParts['nav_bar'] == '1' || $displayParts['sort_lnk'] == '1') {
// - Do not display sort links if less than 2 rows.
// - For a VIEW we (probably) did not count the number of rows
// so don't test this number here, it would remove the possibility
// of sorting VIEW results.
if (isset($unlim_num_rows) && $unlim_num_rows < 2 && !PMA_Table::isView($db, $table)) {
$displayParts['sort_lnk'] = (string) '0';
}
}
// end if (3)
return $displayParts;
}
示例4: PMA_getTableList
/**
* returns array with tables of given db with extended information and grouped
*
* @param string $db name of db
* @param string $tables name of tables
* @param integer $limit_offset list offset
* @param int|bool $limit_count max tables to return
*
* @return array (recursive) grouped table list
*/
function PMA_getTableList($db, $tables = null, $limit_offset = 0, $limit_count = false)
{
$sep = $GLOBALS['cfg']['LeftFrameTableSeparator'];
if (null === $tables) {
$tables = PMA_DBI_get_tables_full($db, false, false, null, $limit_offset, $limit_count);
if ($GLOBALS['cfg']['NaturalOrder']) {
uksort($tables, 'strnatcasecmp');
}
}
if (count($tables) < 1) {
return $tables;
}
$default = array('Name' => '', 'Rows' => 0, 'Comment' => '', 'disp_name' => '');
$table_groups = array();
// for blobstreaming - list of blobstreaming tables
// load PMA configuration
$PMA_Config = $GLOBALS['PMA_Config'];
foreach ($tables as $table_name => $table) {
// if BS tables exist
if (PMA_BS_IsHiddenTable($table_name)) {
continue;
}
// check for correct row count
if (null === $table['Rows']) {
// Do not check exact row count here,
// if row count is invalid possibly the table is defect
// and this would break left frame;
// but we can check row count if this is a view or the
// information_schema database
// since PMA_Table::countRecords() returns a limited row count
// in this case.
// set this because PMA_Table::countRecords() can use it
$tbl_is_view = $table['TABLE_TYPE'] == 'VIEW';
if ($tbl_is_view || PMA_is_system_schema($db)) {
$table['Rows'] = PMA_Table::countRecords($db, $table['Name'], false, true);
}
}
// in $group we save the reference to the place in $table_groups
// where to store the table info
if ($GLOBALS['cfg']['LeftFrameDBTree'] && $sep && strstr($table_name, $sep)) {
$parts = explode($sep, $table_name);
$group =& $table_groups;
$i = 0;
$group_name_full = '';
$parts_cnt = count($parts) - 1;
while ($i < $parts_cnt && $i < $GLOBALS['cfg']['LeftFrameTableLevel']) {
$group_name = $parts[$i] . $sep;
$group_name_full .= $group_name;
if (!isset($group[$group_name])) {
$group[$group_name] = array();
$group[$group_name]['is' . $sep . 'group'] = true;
$group[$group_name]['tab' . $sep . 'count'] = 1;
$group[$group_name]['tab' . $sep . 'group'] = $group_name_full;
} elseif (!isset($group[$group_name]['is' . $sep . 'group'])) {
$table = $group[$group_name];
$group[$group_name] = array();
$group[$group_name][$group_name] = $table;
unset($table);
$group[$group_name]['is' . $sep . 'group'] = true;
$group[$group_name]['tab' . $sep . 'count'] = 1;
$group[$group_name]['tab' . $sep . 'group'] = $group_name_full;
} else {
$group[$group_name]['tab' . $sep . 'count']++;
}
$group =& $group[$group_name];
$i++;
}
} else {
if (!isset($table_groups[$table_name])) {
$table_groups[$table_name] = array();
}
$group =& $table_groups;
}
if ($GLOBALS['cfg']['ShowTooltipAliasTB'] && $GLOBALS['cfg']['ShowTooltipAliasTB'] !== 'nested' && $table['Comment'] && $table['Comment'] != 'VIEW') {
// switch tooltip and name
$table['disp_name'] = $table['Comment'];
$table['Comment'] = $table['Name'];
} else {
$table['disp_name'] = $table['Name'];
}
$group[$table_name] = array_merge($default, $table);
}
return $table_groups;
}
示例5: _setDisplayParts
/**
* Defines the parts to display for the results of a SQL query
*
* @param array $displayParts the parts to display (see a few
* lines above for explanations)
* @param integer &$the_total the total number of rows returned by the SQL
* query without any programmatically appended
* LIMIT clause
* (just a copy of $unlim_num_rows if it exists,
* elsecomputed inside this function)
*
* @return array an array with explicit indexes for all the display
* elements
*
* @access private
*
* @see getTable()
*/
private function _setDisplayParts($displayParts, &$the_total)
{
// 1. Following variables are needed for use in isset/empty or
// use with array indexes or safe use in foreach
$db = $this->__get('db');
$table = $this->__get('table');
$unlim_num_rows = $this->__get('unlim_num_rows');
$num_rows = $this->__get('num_rows');
$printview = $this->__get('printview');
// 2. Updates the display parts
if ($printview == '1') {
$displayParts = $this->_setDisplayPartsForPrintView($displayParts);
} elseif ($this->__get('is_count') || $this->__get('is_analyse') || $this->__get('is_maint') || $this->__get('is_explain')) {
$displayParts = $this->_setDisplayPartsForNonData($displayParts);
} elseif ($this->__get('is_show')) {
$displayParts = $this->_setDisplayPartsForShow($displayParts);
} else {
$displayParts = $this->_setDisplayPartsForSelect($displayParts);
}
// end if..elseif...else
// 3. Gets the total number of rows if it is unknown
if (isset($unlim_num_rows) && $unlim_num_rows != '') {
$the_total = $unlim_num_rows;
} elseif (($displayParts['nav_bar'] == '1' || $displayParts['sort_lnk'] == '1') && (mb_strlen($db) && !empty($table))) {
$the_total = PMA_Table::countRecords($db, $table);
}
// if for COUNT query, number of rows returned more than 1
// (may be being used GROUP BY)
if ($this->__get('is_count') && isset($num_rows) && $num_rows > 1) {
$displayParts['nav_bar'] = (string) '1';
$displayParts['sort_lnk'] = (string) '1';
}
// 4. If navigation bar or sorting fields names URLs should be
// displayed but there is only one row, change these settings to
// false
if ($displayParts['nav_bar'] == '1' || $displayParts['sort_lnk'] == '1') {
// - Do not display sort links if less than 2 rows.
// - For a VIEW we (probably) did not count the number of rows
// so don't test this number here, it would remove the possibility
// of sorting VIEW results.
if (isset($unlim_num_rows) && $unlim_num_rows < 2 && !PMA_Table::isView($db, $table)) {
$displayParts['sort_lnk'] = (string) '0';
}
}
// end if (3)
return $displayParts;
}
示例6: foreach
} else {
$col_cand = $sg;
// None of the candidates where in a where-clause
}
}
// If our array of candidates has more than one member we'll just
// find the smallest table.
// Of course the actual query would be faster if we check for
// the Criteria which gives the smallest result set in its table,
// but it would take too much time to check this
if (count($col_cand) > 1) {
// Of course we only want to check each table once
$checked_tables = $col_cand;
foreach ($col_cand as $tab) {
if ($checked_tables[$tab] != 1) {
$tsize[$tab] = PMA_Table::countRecords($db, $tab, true, false);
$checked_tables[$tab] = 1;
}
$csize[$tab] = $tsize[$tab];
}
asort($csize);
reset($csize);
$master = key($csize);
// Smallest
} else {
reset($col_cand);
$master = current($col_cand);
// Only one single candidate
}
}
// end if (exactly one where clause)
示例7:
// Merge or BerkleyDB table: Only row count is accurate.
if ($is_show_stats) {
$formatted_size = ' - ';
$unit = '';
}
break;
// for a view, the ENGINE is sometimes reported as null,
// or on some servers it's reported as "SYSTEM VIEW"
// for a view, the ENGINE is sometimes reported as null,
// or on some servers it's reported as "SYSTEM VIEW"
case null:
case 'SYSTEM VIEW':
// if table is broken, Engine is reported as null, so one more test
if ($each_table['TABLE_TYPE'] == 'VIEW') {
// countRecords() takes care of $cfg['MaxExactCountViews']
$each_table['TABLE_ROWS'] = PMA_Table::countRecords($db, $each_table['TABLE_NAME'], $force_exact = true, $is_view = true);
$table_is_view = true;
}
break;
default:
// Unknown table type.
if ($is_show_stats) {
$formatted_size = 'unknown';
$unit = '';
}
}
// end switch
if (!PMA_Table::isMerge($db, $each_table['TABLE_NAME'])) {
$sum_entries += $each_table['TABLE_ROWS'];
}
if (isset($each_table['Collation'])) {
示例8: empty
*/
// lem9: we always show the foreign field in the drop-down; if a display
// field is defined, we show it besides the foreign field
$foreign_link = false;
if ($foreigners && isset($foreigners[$field])) {
$foreigner = $foreigners[$field];
$foreign_db = $foreigner['foreign_db'];
$foreign_table = $foreigner['foreign_table'];
$foreign_field = $foreigner['foreign_field'];
// Count number of rows in the foreign table. Currently we do
// not use a drop-down if more than 200 rows in the foreign table,
// for speed reasons and because we need a better interface for this.
//
// We could also do the SELECT anyway, with a LIMIT, and ensure that
// the current value of the field is one of the choices.
$the_total = PMA_Table::countRecords($foreign_db, $foreign_table, TRUE);
if (isset($override_total) && $override_total == true || $the_total < $cfg['ForeignKeyMaxLimit']) {
// foreign_display can be FALSE if no display field defined:
$foreign_display = PMA_getDisplayField($foreign_db, $foreign_table);
$f_query_main = 'SELECT ' . PMA_backquote($foreign_field) . ($foreign_display == FALSE ? '' : ', ' . PMA_backquote($foreign_display));
$f_query_from = ' FROM ' . PMA_backquote($foreign_db) . '.' . PMA_backquote($foreign_table);
$f_query_filter = empty($foreign_filter) ? '' : ' WHERE ' . PMA_backquote($foreign_field) . ' LIKE "%' . PMA_sqlAddslashes($foreign_filter, TRUE) . '%"' . ($foreign_display == FALSE ? '' : ' OR ' . PMA_backquote($foreign_display) . ' LIKE "%' . PMA_sqlAddslashes($foreign_filter, TRUE) . '%"');
$f_query_order = $foreign_display == FALSE ? '' : ' ORDER BY ' . PMA_backquote($foreign_table) . '.' . PMA_backquote($foreign_display);
$f_query_limit = isset($foreign_limit) ? $foreign_limit : '';
if (!empty($foreign_filter)) {
$res = PMA_DBI_query('SELECT COUNT(*)' . $f_query_from . $f_query_filter);
if ($res) {
$the_total = PMA_DBI_fetch_value($res);
@PMA_DBI_free_result($res);
} else {
$the_total = 0;
示例9: PMA_transformation_getOptions
include_once './libraries/transformations/' . $include_file;
if (function_exists('PMA_transformation_' . $transformfunction_name)) {
$transform_function = 'PMA_transformation_' . $transformfunction_name;
$transform_options = PMA_transformation_getOptions(isset($transformation['transformation_options']) ? $transformation['transformation_options'] : '');
$transform_options['wrapper_link'] = PMA_generate_common_url($_url_params);
}
}
$extra_data['transformations'][$cell_index] = $transform_function($column_data, $transform_options);
}
}
// end of loop for each transformation cell
}
// end of loop for each $mime_map
}
/**Get the total row count of the table*/
$extra_data['row_count'] = PMA_Table::countRecords($_REQUEST['db'], $_REQUEST['table']);
$extra_data['sql_query'] = PMA_showMessage($message, $GLOBALS['display_query']);
PMA_ajaxResponse($message, $message->isSuccess(), $extra_data);
}
if (isset($return_to_sql_query)) {
$disp_query = $GLOBALS['sql_query'];
$disp_message = $message;
unset($message);
$GLOBALS['sql_query'] = $return_to_sql_query;
}
$GLOBALS['js_include'][] = 'tbl_change.js';
// in case we call sql.php which needs those:
$GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.16.custom.js';
$active_page = $goto_include;
/**
* If user asked for "and then Insert another new row" we have to remove
示例10: getTableList
/**
* returns array with tables of given db with extended information and grouped
*
* @param string $db name of db
* @param string $tables name of tables
* @param integer $limit_offset list offset
* @param int|bool $limit_count max tables to return
*
* @return array (recursive) grouped table list
*/
public static function getTableList($db, $tables = null, $limit_offset = 0, $limit_count = false)
{
$sep = $GLOBALS['cfg']['NavigationTreeTableSeparator'];
if ($tables === null) {
$tables = $GLOBALS['dbi']->getTablesFull($db, false, false, null, $limit_offset, $limit_count);
if ($GLOBALS['cfg']['NaturalOrder']) {
uksort($tables, 'strnatcasecmp');
}
}
if (count($tables) < 1) {
return $tables;
}
$default = array('Name' => '', 'Rows' => 0, 'Comment' => '', 'disp_name' => '');
$table_groups = array();
foreach ($tables as $table_name => $table) {
// check for correct row count
if ($table['Rows'] === null) {
// Do not check exact row count here,
// if row count is invalid possibly the table is defect
// and this would break left frame;
// but we can check row count if this is a view or the
// information_schema database
// since PMA_Table::countRecords() returns a limited row count
// in this case.
// set this because PMA_Table::countRecords() can use it
$tbl_is_view = $table['TABLE_TYPE'] == 'VIEW';
if ($tbl_is_view || $GLOBALS['dbi']->isSystemSchema($db)) {
$table['Rows'] = PMA_Table::countRecords($db, $table['Name'], false, true);
}
}
// in $group we save the reference to the place in $table_groups
// where to store the table info
if ($GLOBALS['cfg']['NavigationTreeEnableGrouping'] && $sep && strstr($table_name, $sep)) {
$parts = explode($sep, $table_name);
$group =& $table_groups;
$i = 0;
$group_name_full = '';
$parts_cnt = count($parts) - 1;
while ($i < $parts_cnt && $i < $GLOBALS['cfg']['NavigationTreeTableLevel']) {
$group_name = $parts[$i] . $sep;
$group_name_full .= $group_name;
if (!isset($group[$group_name])) {
$group[$group_name] = array();
$group[$group_name]['is' . $sep . 'group'] = true;
$group[$group_name]['tab' . $sep . 'count'] = 1;
$group[$group_name]['tab' . $sep . 'group'] = $group_name_full;
} elseif (!isset($group[$group_name]['is' . $sep . 'group'])) {
$table = $group[$group_name];
$group[$group_name] = array();
$group[$group_name][$group_name] = $table;
unset($table);
$group[$group_name]['is' . $sep . 'group'] = true;
$group[$group_name]['tab' . $sep . 'count'] = 1;
$group[$group_name]['tab' . $sep . 'group'] = $group_name_full;
} else {
$group[$group_name]['tab' . $sep . 'count']++;
}
$group =& $group[$group_name];
$i++;
}
} else {
if (!isset($table_groups[$table_name])) {
$table_groups[$table_name] = array();
}
$group =& $table_groups;
}
$table['disp_name'] = $table['Name'];
$group[$table_name] = array_merge($default, $table);
}
return $table_groups;
}
示例11: _getMasterTable
/**
* Provides the main table to form the LEFT JOIN clause
*
* @param array $all_tables Tables involved in the search
* @param array $all_columns Columns involved in the search
* @param array $where_clause_columns Columns having criteria where clause
* @param array $where_clause_tables Tables having criteria where clause
*
* @return string table name
*/
private function _getMasterTable($all_tables, $all_columns, $where_clause_columns, $where_clause_tables)
{
if (count($where_clause_tables) == 1) {
// If there is exactly one column that has a decent where-clause
// we will just use this
$master = key($where_clause_tables);
return $master;
}
// Now let's find out which of the tables has an index
// (When the control user is the same as the normal user
// because he is using one of his databases as pmadb,
// the last db selected is not always the one where we need to work)
$candidate_columns = $this->_getLeftJoinColumnCandidates($all_tables, $all_columns, $where_clause_columns);
// Generally, we need to display all the rows of foreign (referenced)
// table, whether they have any matching row in child table or not.
// So we select candidate tables which are foreign tables.
$foreign_tables = array();
foreach ($candidate_columns as $one_table) {
$foreigners = PMA_getForeigners($this->_db, $one_table);
foreach ($foreigners as $key => $foreigner) {
if ($key != 'foreign_keys_data') {
if (in_array($foreigner['foreign_table'], $candidate_columns)) {
$foreign_tables[$foreigner['foreign_table']] = $foreigner['foreign_table'];
}
continue;
}
foreach ($foreigner as $one_key) {
if (in_array($one_key['ref_table_name'], $candidate_columns)) {
$foreign_tables[$one_key['ref_table_name']] = $one_key['ref_table_name'];
}
}
}
}
if (count($foreign_tables)) {
$candidate_columns = $foreign_tables;
}
// If our array of candidates has more than one member we'll just
// find the smallest table.
// Of course the actual query would be faster if we check for
// the Criteria which gives the smallest result set in its table,
// but it would take too much time to check this
if (!(count($candidate_columns) > 1)) {
reset($candidate_columns);
$master = current($candidate_columns);
// Only one single candidate
return $master;
}
// Of course we only want to check each table once
$checked_tables = $candidate_columns;
$tsize = array();
$csize = array();
foreach ($candidate_columns as $table) {
if ($checked_tables[$table] != 1) {
$tsize[$table] = PMA_Table::countRecords($this->_db, $table, false);
$checked_tables[$table] = 1;
}
$csize[$table] = $tsize[$table];
}
arsort($csize);
reset($csize);
$master = key($csize);
// Largest
return $master;
}
示例12: _setDisplayMode
//.........这里部分代码省略.........
// "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or
// contains a "PROC ANALYSE" part
$do_display['edit_lnk'] = self::NO_EDIT_OR_DELETE;
// no edit link
$do_display['del_lnk'] = self::NO_EDIT_OR_DELETE;
// no delete link
$do_display['sort_lnk'] = (string) '0';
$do_display['nav_bar'] = (string) '0';
$do_display['ins_row'] = (string) '0';
$do_display['bkm_form'] = (string) '1';
if ($this->__get('_is_maint')) {
$do_display['text_btn'] = (string) '1';
} else {
$do_display['text_btn'] = (string) '0';
}
$do_display['pview_lnk'] = (string) '1';
} elseif ($this->__get('_is_show')) {
// 2.2 Statement is a "SHOW..."
/**
* 2.2.1
* @todo defines edit/delete links depending on show statement
*/
$tmp = preg_match('@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?' . 'PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS' . ')@i', $this->__get('_sql_query'), $which);
if (isset($which[1]) && strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) {
// no edit link
$do_display['edit_lnk'] = self::NO_EDIT_OR_DELETE;
// "kill process" type edit link
$do_display['del_lnk'] = self::KILL_PROCESS;
} else {
// Default case -> no links
// no edit link
$do_display['edit_lnk'] = self::NO_EDIT_OR_DELETE;
// no delete link
$do_display['del_lnk'] = self::NO_EDIT_OR_DELETE;
}
// 2.2.2 Other settings
$do_display['sort_lnk'] = (string) '0';
$do_display['nav_bar'] = (string) '0';
$do_display['ins_row'] = (string) '0';
$do_display['bkm_form'] = (string) '1';
$do_display['text_btn'] = (string) '1';
$do_display['pview_lnk'] = (string) '1';
} else {
// 2.3 Other statements (ie "SELECT" ones) -> updates
// $do_display['edit_lnk'], $do_display['del_lnk'] and
// $do_display['text_btn'] (keeps other default values)
$prev_table = $fields_meta[0]->table;
$do_display['text_btn'] = (string) '1';
for ($i = 0; $i < $this->__get('_fields_cnt'); $i++) {
$is_link = $do_display['edit_lnk'] != self::NO_EDIT_OR_DELETE || $do_display['del_lnk'] != self::NO_EDIT_OR_DELETE || $do_display['sort_lnk'] != '0' || $do_display['ins_row'] != '0';
// 2.3.2 Displays edit/delete/sort/insert links?
if ($is_link && ($fields_meta[$i]->table == '' || $fields_meta[$i]->table != $prev_table)) {
// don't display links
$do_display['edit_lnk'] = self::NO_EDIT_OR_DELETE;
$do_display['del_lnk'] = self::NO_EDIT_OR_DELETE;
/**
* @todo May be problematic with same field names
* in two joined table.
*/
// $do_display['sort_lnk'] = (string) '0';
$do_display['ins_row'] = (string) '0';
if ($do_display['text_btn'] == '1') {
break;
}
}
// end if (2.3.2)
// 2.3.3 Always display print view link
$do_display['pview_lnk'] = (string) '1';
$prev_table = $fields_meta[$i]->table;
}
// end for
}
// end if..elseif...else (2.1 -> 2.3)
}
// end if (2)
// 3. Gets the total number of rows if it is unknown
if (isset($unlim_num_rows) && $unlim_num_rows != '') {
$the_total = $unlim_num_rows;
} elseif (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') && (strlen($db) && !empty($table))) {
$the_total = PMA_Table::countRecords($db, $table);
}
// 4. If navigation bar or sorting fields names URLs should be
// displayed but there is only one row, change these settings to
// false
if ($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') {
// - Do not display sort links if less than 2 rows.
// - For a VIEW we (probably) did not count the number of rows
// so don't test this number here, it would remove the possibility
// of sorting VIEW results.
if (isset($unlim_num_rows) && $unlim_num_rows < 2 && !PMA_Table::isView($db, $table)) {
// force display of navbar for vertical/horizontal display-choice.
// $do_display['nav_bar'] = (string) '0';
$do_display['sort_lnk'] = (string) '0';
}
}
// end if (3)
// 5. Updates the synthetic var
$the_disp_mode = join('', $do_display);
return $do_display;
}
示例13: getTableHtmlForMultipleQueries
/**
* Generate table html when SQL statement have multiple queries
* which return displayable results
*
* @param PMA_DisplayResults $displayResultsObject object
* @param string $db database name
* @param array $sql_data information about SQL statement
* @param string $goto URL to go back in case of errors
* @param string $pmaThemeImage path for theme images directory
* @param string $text_dir text direction
* @param string $printview whether printview is enabled
* @param string $url_query URL query
* @param array $disp_mode the display mode
* @param string $sql_limit_to_append limit clause
* @param bool $editable whether result set is editable
*
* @return string $table_html html content
*/
function getTableHtmlForMultipleQueries($displayResultsObject, $db, $sql_data, $goto, $pmaThemeImage, $text_dir, $printview, $url_query, $disp_mode, $sql_limit_to_append, $editable)
{
$table_html = '';
$tables_array = PMA_DBI_get_tables($db);
$databases_array = PMA_DBI_get_databases_full();
$multi_sql = implode(";", $sql_data['valid_sql']);
$querytime_before = array_sum(explode(' ', microtime()));
// Assignment for variable is not needed since the results are
// looiping using the connection
@PMA_DBI_try_multi_query($multi_sql);
$querytime_after = array_sum(explode(' ', microtime()));
$querytime = $querytime_after - $querytime_before;
$sql_no = 0;
do {
$analyzed_sql = array();
$is_affected = false;
$result = PMA_DBI_store_result();
$fields_meta = $result !== false ? PMA_DBI_get_fields_meta($result) : array();
$fields_cnt = count($fields_meta);
// Initialize needed params related to each query in multiquery statement
if (isset($sql_data['valid_sql'][$sql_no])) {
// 'Use' query can change the database
if (stripos($sql_data['valid_sql'][$sql_no], "use ")) {
$db = PMA_getNewDatabase($sql_data['valid_sql'][$sql_no], $databases_array);
}
$parsed_sql = PMA_SQP_parse($sql_data['valid_sql'][$sql_no]);
$table = PMA_getTableNameBySQL($sql_data['valid_sql'][$sql_no], $tables_array);
$analyzed_sql = PMA_SQP_analyze($parsed_sql);
$is_select = isset($analyzed_sql[0]['queryflags']['select_from']);
$unlim_num_rows = PMA_Table::countRecords($db, $table, true);
$showtable = PMA_Table::sGetStatusInfo($db, $table, null, true);
$url_query = PMA_generate_common_url($db, $table);
list($is_group, $is_func, $is_count, $is_export, $is_analyse, $is_explain, $is_delete, $is_affected, $is_insert, $is_replace, $is_show, $is_maint) = PMA_getDisplayPropertyParams($sql_data['valid_sql'][$sql_no], $is_select);
// Handle remembered sorting order, only for single table query
if ($GLOBALS['cfg']['RememberSorting'] && !($is_count || $is_export || $is_func || $is_analyse) && isset($analyzed_sql[0]['select_expr']) && count($analyzed_sql[0]['select_expr']) == 0 && isset($analyzed_sql[0]['queryflags']['select_from']) && count($analyzed_sql[0]['table_ref']) == 1) {
PMA_handleSortOrder($db, $table, $analyzed_sql, $sql_data['valid_sql'][$sql_no]);
}
// Do append a "LIMIT" clause?
if ($_SESSION['tmp_user_values']['max_rows'] != 'all' && !($is_count || $is_export || $is_func || $is_analyse) && isset($analyzed_sql[0]['queryflags']['select_from']) && !isset($analyzed_sql[0]['queryflags']['offset']) && empty($analyzed_sql[0]['limit_clause'])) {
$sql_limit_to_append = ' LIMIT ' . $_SESSION['tmp_user_values']['pos'] . ', ' . $_SESSION['tmp_user_values']['max_rows'] . " ";
$sql_data['valid_sql'][$sql_no] = PMA_getSqlWithLimitClause($sql_data['valid_sql'][$sql_no], $analyzed_sql, $sql_limit_to_append);
}
// Set the needed properties related to executing sql query
$displayResultsObject->__set('db', $db);
$displayResultsObject->__set('table', $table);
$displayResultsObject->__set('goto', $goto);
}
if (!$is_affected) {
$num_rows = $result ? @PMA_DBI_num_rows($result) : 0;
} elseif (!isset($num_rows)) {
$num_rows = @PMA_DBI_affected_rows();
}
if (isset($sql_data['valid_sql'][$sql_no])) {
$displayResultsObject->__set('sql_query', $sql_data['valid_sql'][$sql_no]);
$displayResultsObject->setProperties($unlim_num_rows, $fields_meta, $is_count, $is_export, $is_func, $is_analyse, $num_rows, $fields_cnt, $querytime, $pmaThemeImage, $text_dir, $is_maint, $is_explain, $is_show, $showtable, $printview, $url_query, $editable);
}
if ($num_rows == 0) {
continue;
}
// With multiple results, operations are limied
$disp_mode = 'nnnn000000';
$is_limited_display = true;
// Collect the tables
$table_html .= $displayResultsObject->getTable($result, $disp_mode, $analyzed_sql, $is_limited_display);
// Free the result to save the memory
PMA_DBI_free_result($result);
$sql_no++;
} while (PMA_DBI_more_results() && PMA_DBI_next_result());
return $table_html;
}
示例14: PMA_getTableList
/**
* returns array with tables of given db with extended infomation and grouped
*
* @uses $GLOBALS['cfg']['LeftFrameTableSeparator']
* @uses $GLOBALS['cfg']['LeftFrameTableLevel']
* @uses $GLOBALS['cfg']['ShowTooltipAliasTB']
* @uses $GLOBALS['cfg']['NaturalOrder']
* @uses PMA_DBI_fetch_result()
* @uses PMA_backquote()
* @uses count()
* @uses array_merge
* @uses uksort()
* @uses strstr()
* @uses explode()
* @param string $db name of db
* return array (rekursive) grouped table list
*/
function PMA_getTableList($db, $tables = null)
{
$sep = $GLOBALS['cfg']['LeftFrameTableSeparator'];
if (null === $tables) {
$tables = PMA_DBI_get_tables_full($db);
if ($GLOBALS['cfg']['NaturalOrder']) {
uksort($tables, 'strnatcasecmp');
}
}
if (count($tables) < 1) {
return $tables;
}
$default = array('Name' => '', 'Rows' => 0, 'Comment' => '', 'disp_name' => '');
$table_groups = array();
foreach ($tables as $table_name => $table) {
// check for correct row count
if (null === $table['Rows']) {
// Do not check exact row count here,
// if row count is invalid possibly the table is defect
// and this would break left frame;
// but we can check row count if this is a view,
// since PMA_Table::countRecords() returns a limited row count
// in this case.
// set this because PMA_Table::countRecords() can use it
$tbl_is_view = PMA_Table::isView($db, $table['Name']);
if ($tbl_is_view) {
$table['Rows'] = PMA_Table::countRecords($db, $table['Name'], $return = true);
}
}
// in $group we save the reference to the place in $table_groups
// where to store the table info
if ($GLOBALS['cfg']['LeftFrameDBTree'] && $sep && strstr($table_name, $sep)) {
$parts = explode($sep, $table_name);
$group =& $table_groups;
$i = 0;
$group_name_full = '';
while ($i < count($parts) - 1 && $i < $GLOBALS['cfg']['LeftFrameTableLevel']) {
$group_name = $parts[$i] . $sep;
$group_name_full .= $group_name;
if (!isset($group[$group_name])) {
$group[$group_name] = array();
$group[$group_name]['is' . $sep . 'group'] = true;
$group[$group_name]['tab' . $sep . 'count'] = 1;
$group[$group_name]['tab' . $sep . 'group'] = $group_name_full;
} elseif (!isset($group[$group_name]['is' . $sep . 'group'])) {
$table = $group[$group_name];
$group[$group_name] = array();
$group[$group_name][$group_name] = $table;
unset($table);
$group[$group_name]['is' . $sep . 'group'] = true;
$group[$group_name]['tab' . $sep . 'count'] = 1;
$group[$group_name]['tab' . $sep . 'group'] = $group_name_full;
} else {
$group[$group_name]['tab' . $sep . 'count']++;
}
$group =& $group[$group_name];
$i++;
}
} else {
if (!isset($table_groups[$table_name])) {
$table_groups[$table_name] = array();
}
$group =& $table_groups;
}
if ($GLOBALS['cfg']['ShowTooltipAliasTB'] && $GLOBALS['cfg']['ShowTooltipAliasTB'] !== 'nested') {
// switch tooltip and name
$table['Comment'] = $table['Name'];
$table['disp_name'] = $table['Comment'];
} else {
$table['disp_name'] = $table['Name'];
}
$group[$table_name] = array_merge($default, $table);
}
return $table_groups;
}
示例15: isset
$tbl_type = $GLOBALS['strView'];
$show_comment = null;
} else {
$tbl_is_view = false;
$tbl_type = isset($showtable['Type']) ? strtoupper($showtable['Type']) : '';
// a new comment could be coming from tbl_operations.php
// and we want to show it in the header
if (isset($submitcomment) && isset($comment)) {
$show_comment = $comment;
} else {
$show_comment = isset($showtable['Comment']) ? $showtable['Comment'] : '';
}
}
$tbl_collation = empty($showtable['Collation']) ? '' : $showtable['Collation'];
if (null === $showtable['Rows']) {
$showtable['Rows'] = PMA_Table::countRecords($GLOBALS['db'], $showtable['Name'], true, true);
}
$table_info_num_rows = isset($showtable['Rows']) ? $showtable['Rows'] : 0;
$auto_increment = isset($showtable['Auto_increment']) ? $showtable['Auto_increment'] : '';
$create_options = isset($showtable['Create_options']) ? explode(' ', $showtable['Create_options']) : array();
// export create options by its name as variables into gloabel namespace
// f.e. pack_keys=1 becomes available as $pack_keys with value of '1'
unset($pack_keys);
foreach ($create_options as $each_create_option) {
$each_create_option = explode('=', $each_create_option);
if (isset($each_create_option[1])) {
${$each_create_option}[0] = $each_create_option[1];
}
}
// we need explicit DEFAULT value here (different from '0')
$pack_keys = !isset($pack_keys) || strlen($pack_keys) == 0 ? 'DEFAULT' : $pack_keys;