Tips for creation of a MySQL database with images

Nov 14, 2007 18:51 GMT  ·  By

Image galleries can help you organize your digital pictures in order to publish them or for indexing purposes. But the best efficient method to manage digital images is to include them in a database. You can choose any type of database to create an image database.

MySQL databases are widely used for many purposes, especially as web applications backend. This type of database can support queries made with any server side programming language, such as PHP, ASP, JSP. First, you must define the database table structure, with the help of a MySQL administration tool. The most popular web browser based MySQL administration tool is phpMyAdmin.

In a previous article I described the installation of phpMyAdmin and the basic steps needed to make a simple MySQL database. After you create a new database, named for example Imagedatabase, you must define tables in which you will introduce new records containing your images. Every new table you will define in phpMyAdmin application must contain the same number of fields (displayed as rows).

The table will represent a certain category for your images and as a consequence, the name should be chosen carefully. For example, let's name the first table MyFirstCategory. For the beginning, let's select only three fields for the new table. After you press the OK button, in the new window, you must define the table fields' properties. For the first field, the name must be set as ID, Type - INT, Extra - auto_increment, the second field will be named Image Title, Type - Varchar, Length - 30, and the last one will be called Image, Type - Blob. The field named ID must be set as primary key, otherwise you will receive an error message.

After you finished to create the first table, copy the SQL corresponding code and then perform the operation again, but this time you change only the table name, in order to define as many categories as you need. Now you are ready to populate the database tables. Select insert new record, then you must operate only on the fields named Title and Image, because the ID will autoincrement itself on every new added record. The Blob type will allow you to insert the images in the database table.

After you finish populating the database, you will be able to manage records with phpMyAdmin administration tool or with another browser-based application that will allow you to browse, edit, add or delete records.