Home arrow PHP arrow Page 3 - Changing Table Structure in phpMyAdmin

BLOB (Binary Large Object) - PHP

This chapter explores editing table definitions and using special column types. When developing Web applications (or any application), requirements often change because of new or modified needs. Developers must accommodate these changes through judicious table-structure editing. This is chapter six of Mastering phpMyAdmin for Effective MySQL Management by Marc Delisle (Packt Publishing, April 2004, ISBN 1904811035).

TABLE OF CONTENTS:
  1. Changing Table Structure in phpMyAdmin
  2. Editing Field Attributes
  3. BLOB (Binary Large Object)
  4. ENUM and SET
  5. Index Management
  6. Multi-Field Indexes and Index Editing
  7. Table Optimization: EXPLAIN a Query
By: Marc Delisle
Rating: starstarstarstarstar / 21
September 28, 2004

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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:

phpMyAdmin

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

phpMyAdmin

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:

phpMyAdmin

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

phpMyAdmin

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

phpMyAdmin

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:

phpMyAdmin

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.

phpMyAdminThis chapter is from Mastering phpMyAdmin for Effective MySQL Management by Marc Delisle (Packt Publishing, April 2004, ISBN 1904811035). Check it out at your favorite bookstore today.

Buy this book now.



 
 
>>> More PHP Articles          >>> More By Marc Delisle
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: