J1.5 talk

Developing a MVC Component/Using the Database: Difference between revisions

From Joomla! Documentation

Jmgonet (talk | contribs)
Where to place the install.sql and uninstall.sql files
 
Jmgonet (talk | contribs)
No edit summary
Line 12: Line 12:


Of course, the files have to be copied in the correct folder (in the example, it should be the ''admin'' folder).
Of course, the files have to be copied in the correct folder (in the example, it should be the ''admin'' folder).
When data is read from a database, it can be retrieved in the class constructor:
  // The constructor accesses the database, and retrieves all properties.
  function __construct($config = array()) {
      parent::__construct($config);          // To transmit configuration to parent class.
      $db =& JFactory::getDBO();
      $query = 'SELECT greeting FROM #__hello';
      $db->setQuery( $query );
      $this->greeting = $db->loadResult();
  }
  // The private property
  var $greeting;
  // The public property accessor
  function getGreeting() {
      return $this->greeting;
  }

Revision as of 19:06, 28 January 2009

Although it is mentioned in the article, I think it is important to underline where the install.sql and uninstall.sql files have to be placed:

install.sql and uninstall.sql files have to be mentioned in two places:

  • In one of the file sections. For example:
  <files folder="admin">
     <filename>...</filename>
     <filename>...</filename>
     <filename>install.sql</filename>
     <filename>uninstall.sql</filename>
  </files>  
  • In the install / uninstall sections.

Of course, the files have to be copied in the correct folder (in the example, it should be the admin folder).

When data is read from a database, it can be retrieved in the class constructor:

  // The constructor accesses the database, and retrieves all properties.
  function __construct($config = array()) {
     parent::__construct($config);           // To transmit configuration to parent class.
     $db =& JFactory::getDBO();		
     $query = 'SELECT greeting FROM #__hello';
     $db->setQuery( $query );
     $this->greeting = $db->loadResult();
  }
  // The private property
  var $greeting;
  // The public property accessor
  function getGreeting() {
     return $this->greeting;
  }