Table of Contents for
Mastering phpMyAdmin 3.4 for Effective MySQL Management

Version ebook / Retour

Cover image for bash Cookbook, 2nd Edition Mastering phpMyAdmin 3.4 for Effective MySQL Management by Marc Delisle Published by Packt Publishing, 2012
  1. Cover
  2. Mastering phpMyAdmin 3.4 for Effective MySQL Management
  3. Mastering phpMyAdmin 3.4 for Effective MySQL Management
  4. Credits
  5. About the Author
  6. About the Reviewers
  7. www.PacktPub.com
  8. Preface
  9. What you need for this book
  10. Who this book is for
  11. Conventions
  12. Reader feedback
  13. Customer support
  14. 1. Getting Started with phpMyAdmin
  15. What is phpMyAdmin?
  16. Installing phpMyAdmin
  17. Configuring phpMyAdmin
  18. Installing phpMyAdmin configuration storage
  19. Upgrading phpMyAdmin
  20. Summary
  21. 2. Configuring Authentication and Security
  22. Securing phpMyAdmin
  23. Summary
  24. 3. Over Viewing the Interface
  25. Customizing general settings
  26. Character sets and collations
  27. Navigation panel
  28. Main panel
  29. User preferences
  30. Query window
  31. Summary
  32. 4. Creating and Browsing Tables
  33. Creating our first table
  34. Inserting data manually
  35. Browse mode
  36. Profiling queries
  37. Creating an additional table
  38. Summary
  39. 5. Changing Data and Structure
  40. Changing table structure
  41. Summary
  42. 6. Exporting Structure and Data (Backup)
  43. Exporting a database
  44. Exporting a table
  45. Exporting selectively
  46. Exporting multiple databases
  47. Saving the export file on the server
  48. Memory limits
  49. Summary
  50. 7. Importing Structure and Data
  51. Importing SQL files
  52. Importing CSV files
  53. Importing other formats
  54. Reading files from a web server upload directory
  55. Displaying an upload progress bar
  56. Summary
  57. 8. Searching Data
  58. Performing a complete database search
  59. Stopping an errant query
  60. Summary
  61. 9. Performing Table and Database Operations
  62. Changing table attributes
  63. Emptying or deleting a table
  64. Renaming, moving, and copying tables
  65. Performing other table operations
  66. Multi-table operations
  67. Database operations
  68. Summary
  69. 10. Benefiting from the Relational System
  70. Defining relations with the relation view
  71. Defining relations with the Designer
  72. Benefiting from the defined relations
  73. Column commenting
  74. Summary
  75. 11. Entering SQL Statements
  76. The Query window
  77. Multi-statement queries
  78. Pretty printing (syntax highlighting)
  79. The SQL Validator
  80. Summary
  81. 12. Generating Multi-table Queries
  82. Exploring column criteria
  83. Generating automatic joins (internal relations)
  84. Executing the query
  85. The visual builder
  86. Summary
  87. 13. Synchronizing Data and Supporting Replication
  88. Supporting MySQL replication
  89. Summary
  90. 14. Using Query Bookmarks
  91. Creating bookmarks
  92. Recalling bookmarks from the bookmarks list
  93. Passing a parameter to a bookmark
  94. Summary
  95. 15. Documenting the System
  96. Generating relational schemas
  97. Summary
  98. 16. Transforming Data using MIME
  99. Enabling transformations
  100. Examples of transformations
  101. Summary
  102. 17. Supporting Features Added in MySQL 5
  103. Supporting routines—stored procedures and functions
  104. Executing code with triggers
  105. Using information_schema
  106. Partitioning
  107. Exploring the event scheduler
  108. Summary
  109. 18. Tracking Changes
  110. Prerequisites
  111. Principles
  112. Initiating tracking for one table
  113. Testing the tracking mechanism
  114. Determining tracking status
  115. Structure snapshot
  116. Exporting a version
  117. Creating a new version
  118. Deleting tracking information
  119. Summary
  120. 19. Administrating the MySQL Server
  121. Database information
  122. Server information
  123. Summary
  124. A. Troubleshooting and Support
  125. Seeking support
  126. Contributing to the project

Generating relational schemas

In Chapter 10, we defined relations between the book and author tables. These relations were used for various foreign key functions (for example, getting a list of possible values in Insert mode). We will now examine a feature that enables us to generate a custom-made relational schema for our tables in the popular PDF format and other formats as well. This feature requires that the phpMyAdmin configuration storage be properly installed and configured.

Adding a third table to our model

To get a more complete schema, we will now add another table, country, to our database. The following block of code displays the contents of its export file:

CREATE TABLE IF NOT EXISTS `country` (
`code` char(2) NOT NULL,
`description` varchar(50) NOT NULL,
PRIMARY KEY (`code`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO `country` (`code`, `description`) VALUES
('ca', 'Canada'),
('uk', 'United Kingdom');

We will now link this table to the author table. First, in the Relation view for the country table, we specify the column that we want to display, and then click on Save.

Adding a third table to our model

We then add a country_code column (same type and size as that of the code column in the country table) to the author table, and in the Relation view, we link it to the newly-created country table.

Note

We must remember to click on Save for the relation to be recorded.

For this example, it's not necessary to enter any country data for an author, as we are interested only in the relational schema.

Adding a third table to our model

Producing schema pages

Each relational schema is called a page. We can create or edit a page by clicking on Edit or export relational schema in the Operations page of the Database view.

Page planning

A relational schema cannot span multiple databases. But even working with just one database, the number of tables might be large. Representing the various table relations in a clear way could be a challenge. This is why we may use many pages, each showing some tables and their relations.

We must also take into account the dimensions of the final output. Printing on letter-size paper gives us less space to show all of our tables and still have a legible schema.

Creating a new page

As there are no existing pages, we need to create one. As our most important table is book, we will also name this page book.

We will choose which tables we wish to see in the relational schema. We could choose each table individually. However, for a good start, checking the appropriate Automatic layout checkbox is recommended. Doing this puts all the related tables from our database onto the list of tables to be included in the schema. It then generates appropriate coordinates so that the tables will appear in a spiral layout, starting from the center of the schema. These coordinates are expressed in millimeters, with (0, 0) being located at the upper-left corner. We then click on Go:

Creating a new page

Editing a page

We now get a page with three different sections. The first one is the page menu, where we choose the page on which we want to work (from the drop-down menu). We can also delete the chosen page. We could also eventually create a second schema (page).

Editing a page

The next section is the table placement portion. We can now see the benefit of the Automatic layout feature—we already have our three tables selected, with the X and Y coordinate columns filled in. We can add a table (on the last line), delete a table (using the checkbox), and change the coordinates (which represent the position of the upper-left corner of each table on the schema):

Editing a page

To help set exact coordinates, a visual editor is available for JavaScript-enabled browsers. The editor appears when the Toggle scratchboard button is clicked once. It will disappear when this button is clicked again. We can drag and drop tables on the scratchboard, and the coordinates will change accordingly. The appearance of the tables on the scratchboard provides a rough guide to the final PDF output. Some people prefer to see only the table names (without every column name) on the scratchboard. This can be done by deselecting the Column names checkbox and then clicking on Save. The following image shows an example of this scratchboard:

Editing a page

Note

When we are satisfied with the layout, we must click on Save.

Exporting a page for display

The last section of the screen is the report generation dialog. Now that we have created a page, the Display relational schema shows a dialog as seen in the following screenshot:

Exporting a page for display

The available options are:

Option

Description

Select Export Relational Type

Permits to choose the file format to export to (PDF, SVG, DIA, Visio, or EPS).

Show grid

The schema will have a grid layer with the coordinates displayed. Useful when designing and testing the schema.

Show color

The links, table names, and special columns (primary keys and display columns) will be in color.

Show dimension of tables

The visual dimension of each table in the table title (for example, 32x30) will be displayed. This is useful when designing and testing the schema.

Display all tables with the same width

All tables will be displayed using the same width. (Normally, the width adjusts itself according to the length of the table and column names.)

Data Dictionary

The data dictionary, which was covered earlier in this chapter, will be included at the beginning of the report.

Only show keys

Does not show the columns on which there are no indexes defined.

Orientation

Here, we choose the printed orientation of the report

Paper size

Changing this option will influence the schema and the scratchboard dimensions.

In config.inc.php, the following parameters define the available paper sizes and the default choice:

$cfg['PDFPageSizes'] = array('A3', 'A4', 'A5', 'letter', 'legal');
$cfg['PDFDefaultPageSize'] = 'A4';

The following screenshot shows the last page of the generated report (the schema page) in PDF format. The first four pages contain the data dictionary along with an additional feature.

Arrows point in the direction of the corresponding foreign table. If Show color checkbox has been ticked, the primary keys are shown in red and the display columns in blue, as shown in the following screenshot:

Exporting a page for display

The following screenshot provides another example generated from the same book table's PDF page definition. This time the grid is shown, but not the colors:

Exporting a page for display

Changing the font in PDF schema

All the text we see in the PDF schema is drawn using a specific font. phpMyAdmin uses the DejaVuSans font (http://dejavu.sourceforge.net), which covers a wide range of characters.

For actual PDF generation, phpMyAdmin relies on the tcpdf library (http://tcpdf.sourceforge.net). This library has two ways of using fonts—embedded and not embedded. Embedding fonts will produce a bigger PDF file because the whole font is included in the PDF file. This is the default option chosen by phpMyAdmin because the library does not depend on the presence of a specific TrueType font in the client operating system.

The fonts are located in libraries/tcpdf/fonts under the main phpMyAdmin directory.

To use a different font file, we must first add it to the library (tools are present in the original tcpdf kit and a tutorial is available on the http://www.fpdf.org website) and then modify phpMyAdmin's libraries/schema/ Pdf_Relation_Schema.class.php source code.

Laying out a schema with the Designer feature

The Designer feature (available in the Database view) offers a more refined way of moving the tables on screen, as the column links follow the table movements. Therefore, an interface exists between the tables' coordinates, as saved by the Designer, and the coordinates for the schema. Let us enter the Designer and click on the small PDF logo.

This brings us to a panel where we can choose the (existing) schema name and the action we want to perform—in our case, to export the Designer coordinates to the schema definition. We could also use the New page name dialog, entering a page name, and then clicking on Go to create an empty page. From here, we can subsequently export the coordinates saved from the Designer workspace:

Laying out a schema with the Designer feature

Note

There is a difference in the span of tables managed by the Designer and by the Edit or export relational schema feature. The Designer manipulates, by default, every table of a database, whereas the Edit or export relational schema panel offers us a choice of tables, enabling us to represent a subset of the relations if there are many tables.