TEXT Fields

We will now explore how to use the TEXT field type and the relevant configuration values to adjust for the best possible phpMyAdmin behavior.

First we add a TEXT field called description:

There are three parameters that control the layout of the text area that will be displayed in Insert or Edit mode for the TEXT fields.

First, the number of columns and rows for each field is defined by:

$cfg['TextareaCols'] = 40;

$cfg['TextareaRows'] = 7;

This gives (by default) the following space to work on a TEXT field:

The settings do not impose a limit other than visual, and a vertical scroll bar is created by the browser, should it be necessary.

Although MEDIUMTEXT, TEXT, and LONGTEXT columns can accommodate more than 32K of data, current browsers cannot always edit them with the mechanism offered by HTML: a text area. In fact, experimentation has convinced the phpMyAdmin development team to have the product display a warning message if the contents are larger than 32K, telling users that it might not be editable.

For LONGTEXT fields, setting $cfg['LongtextDoubleTextarea'] to TRUE doubles the available editing space.

BLOB (Binary Large Object)

BLOB fields are usually used to hold some binary data (image, sound), even though the MySQL documentation implies that even TEXT fields could be used for the same purpose. However, phpMyAdmin's intention is to work with BLOB fields to hold all binary data.

We will see in Chapter 16, MIME-Based Transformations that there are special mechanisms available to go further with BLOB fields, including being able to view some images directly from within phpMyAdmin.

First we add a BLOB field, cover_photo, to our books table:

If we now Browse the table, we can see the field length information [BLOB – 0 Bytes] for each BLOB field:

This is because the $cfg['ShowBlob'] configuration directive is set to FALSE by default, thus blocking the display of BLOB contents in Browse and Edit modes (and showing a Binary – do not edit warning). This behavior is intentional—usually we cannot do anything with binary data represented in plain text.

Binary Contents Upload

If we now edit one row, we see the warning and a Browse button. Even though editing is not allowed, we can easily upload a text or binary file into this BLOB column.

Let's choose an image file using the Browse button—for example, the pma_logo.png file in the phpMyAdmin/images directory:

We have now uploaded an image inside this field, for a specific row:

If $cfg['ShowBlob'] is set to TRUE, we see the following in the BLOB field:

The $cfg['ProtectBinary'] parameter controls what can be done while editing binary fields (BLOBs and any other field with the binary attribute).

The default value 'blob' permits us to protect against editing of BLOB fields, allowing us to edit other fields marked as binary by MySQL. A value of 'all' would protect against editing even BLOB fields. A value of FALSE would protect nothing, thus allowing us to edit all fields. If we try the last choice, we see the following in the Edit panel for this row:

Chances are this is not our favorite image editor! In fact, data corruption may result even if we save this row without touching the BLOB field. But the setting to remove ProtectBinary exists because some users put text in their BLOBs and must be allowed to modify them.

MySQL BLOB data types are actually similar to their corresponding TEXT data types, with the only difference of being treated as case-sensitive for sorting and comparison purposes. This is why phpMyAdmin can be configured to allow editing of BLOB fields.

 

<< Back to Part 1 | Continue to PhpMyAdmin Part Three >>

 

© Copyright 2003-2023 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.