Actions

J1.5 talk

Difference between revisions of "Developing a MVC Component/Using the Database"

From Joomla! Documentation

(Some glitches)
m (Saving the install/uninstall files: new section)
Line 45: Line 45:
 
(both glitches are not in the attachment belonging to the article; the component file: com_hello3_01 is correct)<br>
 
(both glitches are not in the attachment belonging to the article; the component file: com_hello3_01 is correct)<br>
 
--[[User:M.A.S.H|M.A.S.H]] 12:09, 2 August 2009 (UTC)
 
--[[User:M.A.S.H|M.A.S.H]] 12:09, 2 August 2009 (UTC)
 +
 +
== Saving the install/uninstall files ==
 +
 +
On my system I ran into a problem with the intall.sql / uninstall.sql files.
 +
I wanted to avoid using the <query> tags by including them in the script and having JIntaller run them. I created files using MySQL Query Browser testing them to make sure they worked.
 +
When the component is installed JInstaller raises a 1064 db error, which did not make any sense.
 +
The problem was occurring because I was saving the script as type "SQL Script File UTF-8", which seemed logical because the charset is utf8. The file must be saved as type "SQL Script File ANSI" or you get the 1064 db error.
 +
 +
Using Joomla 1.5.14, MSQL Query Browser 1.2.12, XP sp3
 +
 +
[[User:Exps1|Exps1]] 13:43, 15 October 2009 (UTC)

Revision as of 08:43, 15 October 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;
  }

/* 2009-07-21 */

  • Are those file names for "install.utf8.sql" and "uninstall.utf8.sql" correctly written into XML file? I see files "install.sql" and "uninstall.sql", but in the text, there says the files will be named "install.utf8.sql" and "uninstall.utf8.sql"?

Some glitches

I followed the MVC explanation step by step but this section contains some glitches.

The .sql files should NOT contain '.utf' in the file names. The installer will not find the files (verified on Joomla! 1.5.12).

As indicated above, storing the (un)instal.sql should be in admin directory. So to be concrete the last lines of the chapters "Creating the Installation SQL File" and "Creating the uninstall SQL file" should be:

We will ... called ./admin/install.sql
We will ... called ./admin/uninstall.sql

(both glitches are not in the attachment belonging to the article; the component file: com_hello3_01 is correct)
--M.A.S.H 12:09, 2 August 2009 (UTC)

Saving the install/uninstall files

On my system I ran into a problem with the intall.sql / uninstall.sql files. I wanted to avoid using the <query> tags by including them in the script and having JIntaller run them. I created files using MySQL Query Browser testing them to make sure they worked. When the component is installed JInstaller raises a 1064 db error, which did not make any sense. The problem was occurring because I was saving the script as type "SQL Script File UTF-8", which seemed logical because the charset is utf8. The file must be saved as type "SQL Script File ANSI" or you get the 1064 db error.

Using Joomla 1.5.14, MSQL Query Browser 1.2.12, XP sp3

Exps1 13:43, 15 October 2009 (UTC)