Mastering phpMyAdmin 3.3.x for Effective MySQL Management
上QQ阅读APP看书,第一时间看更新

Browse mode

There are many ways to enter Browse mode. In fact, it's used each time the query results are displayed. We can enter this mode by clicking on the table name in the navigation panel, or by clicking on Browse when we are in the Table view for a specific table:

Browse mode

SQL query links

In the Browse results, the first part displayed is the query itself, along with a few links. The displayed links may vary depending on our actions and some configuration parameters.

SQL query links

The Profiling checkbox is covered in Chapter 17,Supporting MySQL 5.0 and 5.1.

The Edit link appears if $cfg['SQLQuery']['Edit'] is set to TRUE. Its purpose is to open the Query window so that you can edit this query (see Chapter 11, Entering SQL Commands, for more details).

Explain SQL is displayed if $cfg['SQLQuery']['Explain'] is set to TRUE. We will see in Chapter 5, Changing Data and Structure what this link can be used for.

The Create PHP Code link can be clicked to reformat the query to the syntax expected in a PHP script. It can then be copied and pasted directly at the place where we need the query in the PHP script we are working on. Note that after a click, this link changes to Without PHP Code, which would bring back the normal query display. This link is available if $cfg['SQLQuery']['ShowAsPHP'] is set to TRUE.

SQL query links

Refresh is used to execute the same query again. The results might change, as a MySQL server is a multi-user server, and other users or processes might be modifying the same tables. This link is shown if $cfg['SQLQuery']['Refresh'] is set to TRUE.

All four of these parameters have a default value of TRUE in config.inc.php.

Navigation bar

The Navigation bar is displayed at the top of the results and also at the bottom. Column headers can be repeated at certain intervals among results depending on the value entered in repeat headers after....

Navigation bar

The Navigation bar enables us to navigate from page to page, displaying an arbitrary number of records (or rows), starting at some point in the results. As we entered browse mode by clicking on Browse, the underlying query that generated the results includes the whole table. However, this is not always the case.

Notice that we are positioned at record number 0, and are seeing records in horizontal mode.

The default display mode is'horizontal', as defined in $cfg['DefaultDisplay']. We can also set this to'vertical' if we usually prefer this mode. Even if our preferred mode is set in this configuration parameter, we can always use the Show dialog to change it on the fly.

Navigation bar

Another possibility for $cfg['DefaultDisplay'] is the'horizontalflipped' value (which can also be selected on screen via the horizontal (rotated headers) choice), which rotates the column headers by 90 degrees. If we try this choice, another parameter, $cfg['HeaderFlipType'], plays a role. Its default value, css, displays true rotated headers. Not every browser supports this (at least Firefox and Chrome do not); however, Internet Explorer 8 and Opera do support this feature, and produce:

Navigation bar

On other browsers, it seems the best we can achieve is by setting $cfg['HeaderFlipType'] to fake.

Navigation bar

We are currently using a table containing a small number of rows. With larger tables, we could see a more complete set of navigation buttons. To simulate this, let's use the Show dialog to change the default number of rows from 30 to 1; we then click on Show. We can see that the navigation bar adapts itself:

Navigation bar

This time, there are buttons labeled<<, <, >, and>> for easy access to the first page, previous page, next page, and the last page of the results respectively. The buttons appear only when necessary; for example, the first page button is not displayed if we already are on the first page. These symbols are displayed in this manner as the default setting of $cfg['NavigationBarIconic'] is TRUE. A FALSE here would produce buttons like Next and End, whereas a value of'both' would display> Next and>> End.

There is also a Page number drop-down menu, to go directly to one of the pages located near the current page. As there can be hundreds or thousands of pages, this menu is kept small and contains the commonly requested pages: A few page numbers before and after the current page, a few pages at the beginning and at the end, and a sample of page numbers based on a computed interval.

By design, phpMyAdmin always tries to give quick results, and one way to achieve this result is to add a LIMIT clause in SELECT. If a LIMIT clause is already there in the original query, phpMyAdmin will respect it. The default limit is 30 rows, set in $cfg['MaxRows']. If there are many users on the server, limiting the number of rows returned helps to keep the server load to a minimum.

Another button is available on the navigation bar, but must be activated by setting $cfg['ShowAll'] to TRUE. It would be very tempting for users to use this button often. Hence, on a multi-user installation of phpMyAdmin, it's recommended that the button be left to its default value of disabled (FALSE). When enabled, the navigation bar is augmented with a Show all button. Clicking on this button retrieves all of the rows of the current results set, which might hit the execution time limit in PHP or a memory limit on the server; most browsers would also crash when asked to display thousands of rows. The exact number of rows that can be safely displayed cannot be predicted as it depends on the actual data present in columns and on the browser's capabilities.

Note

If we enter a big number in the Show...rows dialog, the same results will be achieved (and we may face the same problems).

Query results operations

A section labeled Query results operations is located under the results. This contains links to print the results (with or without the FULL TEXT columns), to export these results (see the Exporting partial query results section in Chapter 6, Exporting Data and Structure (Backup)), or to create a view from this query (more on this in Chapter 17, Supporting MySQL 5.0 and 5.1).

Sorting results

In SQL, we can never be sure of the order in which the data is retrieved, unless we explicitly sort the data. Some implementations of the retrieving engine may show results in the same order as the one in which data was entered, or according to a primary key. However, a sure way to get results in the order we want is by sorting them explicitly.

When browsing results are displayed, any column header can be clicked to sort on this column, even if it's not part of an index. Let's click on the author_id column header:

Sorting results

We can confirm that the sorting has occurred, by watching the SQL query at the top of the screen; it now contains an ORDER BY clause.

We now see a small red triangle pointing upwards beside the author_id header. This means that the current sort order is "ascending". Moving the mouse cursor over the author_id header makes the red triangle change direction, to indicate what will happen if we click on the header again—a sort by descending author_id.

Another way to sort is by key. The Sort dialog shows all of the keys already defined. Here we see a key named PRIMARY—the name given to our primary key on the isbn field when we checked Primary for this field at creation time:

Sorting results

This might be the only way to sort on multiple fields at once (for multi-field indexes).

The default initial sort order is defined in $cfg['Order'], with ASC for ascending, DESC for descending. The sort order can also be SMART, which means that fields of type DATE, TIME, DATETIME, and TIMESTAMP would be sorted in descending order, whereas other field types will be sorted in ascending order.

Headwords

Because we can change the number of records displayed on a page, it's quite possible that we do not see all of the data. In this case, it would help to see headwords—indications about the first and last row of displayed data. This way, you can click on Next or Previous without scrolling to the bottom of the window.

However, which column should phpMyAdmin base this headwords generation on? A simple assumption has been made: If you click on a column's header to indicate your intention of sorting on this column, phpMyAdmin uses this column's data as a headword. For our current book table, we do not have enough data to clearly notice the benefits of this technique. However, we can nonetheless see that after a sort the top part of the screen now contains this message:

Showing rows 0 - 1 (2 total, Query took 0.0006 sec) [author_id: 1 - 2]

Here, the message between square brackets means that author_id number 1 is on the first displayed row and number 2 is on the last one.

Color-marking rows

When moving the mouse between rows, the row background color can change to the color defined in $cfg['BrowsePointerColor']. This parameter can be found in themes/themename/layout.inc.php. To enable this, the browse pointer for all themes—$cfg['BrowsePointerEnable']—must be set to TRUE (the default) in config.inc.php.

It may be interesting to visually mark some rows when we have many columns in the table and must constantly scroll left and right to read data. Another option is to highlight the importance of some rows for personal comparison of data, or when showing data to people. Highlighting is done by clicking on the row. Clicking again removes the highlighting from the row. The chosen color is defined by $cfg['BrowseMarkerColor'] (see themes/themename/layout.inc.php). This feature must be enabled by setting $cfg['BrowseMarkerEnable'] to TRUE, this time in config.inc.php. This sets the feature for all themes. We can mark more than one row. Marking the row also activates the checkbox for this row.

Color-marking rows

Limiting the length of each column

In the previous examples, we always saw the full contents of each column, as each column had a number of characters that was within the limit defined by $cfg['LimitChars']. This is a limit enforced on all non-numeric fields. If this limit was lower (say 10), the display would be as follows:

Limiting the length of each column

This would help us see more columns at the same time (at the expense of seeing less of each column).

Display options

In order to see the full texts, we will now make use of the Options slider, which reveals some display options. The option that concerns us at the moment is the Partial Texts/Full Texts pair; we can choose Full Texts to see all of the text that was truncated. Even if we elect not to change the $cfg['LimitChars'] parameter, there will be a time when asking for full texts will be useful (when we work with the TEXT field type—more on this in Chapter 5,Changing Data and Structure).

A quicker way of seeing the full texts is to click on the big T, which is located just on top of the Edit and Delete icons. Another click on this T toggles the display from full to partial.

Browsing distinct values

There is a quick way to display all distinct values and the number of occurrences for each value for each field. This feature is available on the Structure page. For example, we want to know how many different authors we have in our book table and how many books each one wrote. On the line describing the field we want to browse (here author_id), we click on the Browse distinct values icon or link:

Browsing distinct values

We have a limited test set, but can nonetheless see the results:

Browsing distinct values

Customizing the browse mode

The following are additional parameters that control the appearance of results. These parameters—except $cfg['RepeatCells']—are located in themes/themename/layout.inc.php.

Additional parameter

Effect on appearance of result

$cfg['Border']

The HTML tables used to present results have no border by default because this parameter is set to 0; we can set this to a higher number (for example, 1 or 2) to add borders to the tables.

$cfg['ThBgcolor']

The tables mentioned have headers with #D3DCE3 as the default background color.

$cfg['BgcolorOne'], $cfg['BgcolorTwo']

When displaying rows of results, two background colors are used alternately; by default, those are #CCCCCC and #DDDDDD.

$cfg['RepeatCells']

When many rows of data are displayed, we may lose track of the meaning of each column. By default, at each 100th cell, the column headers are displayed.