Version 7, last updated by chay at June 12, 2011 17:47 UTC

Let's define the basic database schema for our component. Execute the following SQL statement in your MySQL client, such as PHPMyAdmin. Before doing so, replace the prefix '#_' with the prefix you chose during Joomla installation. The default is 'jos'.

CREATE TABLE IF NOT EXISTS `#__blog_posts` (
  `blog_post_id` SERIAL,
  `title` varchar(255) NOT NULL,
  `text` mediumtext NOT NULL
);

Naming conventions

The name of the table is #__blog_posts. 'blog' is the name of our component, followed by the name of the entity we want to store in this table. This name should always be plural; a table is always a collection of items. So the database table naming convention is: "dbprefix_componentname_entities".

Next we have the primary key. Every table should have one. We define it as SERIAL, which is an alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE.

The name of the primary key is blog_post_id. Again we use the component's name 'blog', followed by the name of the entity, in singular this time, since it describes one item. In other words the primary key name format is "componentname_entity_id"

Now we insert some sample data into the blog table. Replace #__ with your database prefix:

INSERT INTO `#__blog_posts` (`title`, `text`) VALUES
    ('Blog post one', 'This is the first post'),
    ('Blog post two', 'This is the second post'),
    ('Blog post three', 'This is the third post');

Now we have a database defined let's delete the controller we created in the previous part. For this delete the controllers folder and enclosed file in:

 /components/com_blog/controllers/blog.php

Registering the component

Finally the component must be registered in the database (however, this is done automatically when installing a new component with the normal procedure through the Joomla installer)

To do this, insert the following code in the database. Replace '#_' with your database prefix ('jos' by default):

For Joomla 1.5

INSERT INTO `#__components` ( `id`, `name`, `link`, `menuid`, `parent`, 
`admin_menu_link`, `admin_menu_alt`, `option`, `ordering`, `admin_menu_img`, 
`iscore`, `params`, `enabled`) 
VALUES(NULL, 'Blog', 'option=com_blog', 0, 0,'option=com_blog', 'Blog', 
'com_blog', 0, '', 0, '', 1)

For Joomla 1.6

INSERT INTO `#__extensions`    ( `extension_id`, `name`, `type`, `element`,
`folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, 
`params`, `custom_data`, `system_data`, `checked_out`, `checked_out_time`, 
`ordering`, `state`) VALUES(NULL, 'com_blog', 'component',
'com_blog', '', '1', '1', '1', '0', '', '', '', '', 0, '0000-00-00 00:00:00','0','0');