Archive for the ‘mysql’ Category.

Easy Image Class

I needed something simple to grab images from MySQL database and display them. Slowly it grew into a very handy class.

This class can be used to manipulate images stored in files or in a MySQL database. It can read images from files and store them in a MySQL database table, and vice-versa. The class can also convert images between GIF, JPEG and PNG formats, as well resize the images to create thumbnails.

Documentation:
Coming Soon…

MySQL BLOB Field

When I needed to know some basic information on BLOBs, I had very hard time finding it. Nearly every site I could not entirely understand at first glance. A BLOB is a “binary large object”; when using phpMyAdmin, you will see an upload form to insert a BLOB. Here is the maximum file sizes you can store in different blob fields in MySQL database.

Type Sizes
TINYBLOB 256 Bytes
BLOB 65,536 Bytes 64 KB
MEDIUMBLOB 16,777,216 Bytes 16,384 KB 16 MB
LARGEBLOB 4,294,967,296 Bytes 4096 MB 4 GB

Easy way to calculate exact sizes:
3 GB = 3 * 1024 * 1024 * 1024
4 MB = 4 * 1024 * 1024
2 KB = 2 * 1024

In many manuals for MySQL the limit is stated in characters, for BLOBs it is: 1 Character = 1 Byte

If you store a 2 MB picture in a MEDIUMBLOB and then change the field to BLOB, the picture will be cut off. Here is what you will get if you try opening teh image with gd library after fetching from database:

php php-cut-off

On the left is original uploaded or inserted image and on the right is what was actually stored from the inserted one and outputted with PHP GD library; using imagecreatefromstring() to make the image from the string fetched from the database.

Attached Files: