phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Joomla - Component: Creating the Database Table

Tag: joomla, cms, Joomla Component   Category: PHP Framework
post: 04 Nov 2007 read: 5,508


Now, we create a table for preparing place where data will go. For first time, make sure what prefix database you use. You can check on menu Site > Global Configuration > Server. Assuming, that your database prefix is jos_.

Joomla: Look database prefix

If you prefer SQL statement, you can write following code:


CREATE TABLE `jos_hello` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`message` TEXT NOT NULL ,
`published` TINYINT( 1 ) NOT NULL 
);

If you prefer use web-based database manager such phpMyAdmin, folow this steps:

  1. Open your phpMyAdmin.
  2. Select you Joomla! database.
  3. Register new table on form like following images:
    Joomla: Register new table
    Click go.
  4. You will get a form for define columns. Do like following images:
    Joomla: define columns

    Don't forget define primary key and auto_increment for id.
    Joomla: define primary key and auto increment

    Click Save button.

Creating a Table Class

We could write individual functions to take care of the queries necessary to add, update, and delete data. Fortunately, the Joomla! team has ready done this for you. The JTable class provides functions for performing modify data from single table in the database. We just extend the class.

Following steps to create table class:

  1. Create a folder named "tables" within administrator/components/com_hello.
  2. Create the hello.php file and enter the following code:
    
    <?php
    defined('_JEXEC') or die('Restricted Access');
    
    class TableHello extends JTable
    {
    	var $id 		= null;
    	var $message 		= null;	
    	var $published 		= 0;	
    	
    	/**
    	* @param database A database 
            connector object */
    	function __construct(&$db)
    	{
    		parent::__construct( '#__hello', 'id', $db );
    	}	
    	
    }
    
    ?>
    


Series this article:
Joomla - Component: Create Hello World Component on Front End
Joomla - Component: Create Hello World Component on Back End
Joomla - Component: Registering Your Component in database
Joomla - Component: Create Component Link for Front End
Joomla - Component: Creating Toolbars
Joomla - Component: Available Toolbar Buttons
Joomla - Component: Creating the Database Table
Joomla - Component: Creating Form Input Data at Back End
Joomla - Component: Saving Data to Database
Joomla - Component: Creating a List Screen
Joomla - Component: Creating Advance List Screen
Joomla - Component: Editing Data
Joomla - Component: Deleting Data
Joomla - Component: Updating publish state
Joomla - Component: Hello From Database at Front End
Joomla - Component: a Hello page
Joomla - Component: Generating Friendly Links
Joomla - Component: Adding Comment ( Create Table )
Joomla - Component: Adding Comment (Create Form)
Joomla - Component: Adding Comment ( Insert Data )
Joomla - Component: Adding Comment ( Displaying Comments )
Joomla: Fast Road to Understand Component Programming

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

2 Responses to Joomla - Component: Creating the Database Table:

very good I hope there is more tutorials

Thanks

These posts are very useful.Thank you very much.
But Iam facing problem when Iam adding more columns to the table.
Can you please help in this regard

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting