jerry jerry - 3 years ago 218
MySQL Question

Joomla Module Install mySQL

I am creating a new module, but this time I got an error while creating my database table. Also I am a kind of confused about the file structure for installing this. I have read the Joomla documentation and tried what they're saying:

In my manifest I created the following install/remove (SQL) sections:

<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="3.1.0" client="site" method="upgrade">
<name>Modulename</name>
<author>Jerry Schirrmann</author>
<description>A test module</description>
<files>
<filename>mod_modulename.xml</filename>
<filename module="mod_modulename">mod_modulename.php</filename>
<filename>index.html</filename>
<filename>helper.php</filename>
<filename>tmpl/default.php</filename>
<filename>tmpl/index.html</filename>
<filename>sql/mysql/install.mysql.utf8.sql</filename>
<filename>sql/mysql/uninstall.mysql.utf8.sql</filename>
</files>
<config>
<install>
<sql>
<file driver="mysql" charset="utf8">sql/mysql/install.mysql.utf8.sql</file>
<file driver="sqlazure" charset="utf8">sql/sqlazure/install.sqlazure.utf8.sql</file>
</sql>
</install>

<uninstall>
<sql>
<file driver="mysql" charset="utf8">sql/mysql/uninstall.mysql.utf8.sql</file>
<file driver="sqlazure" charset="utf8">sql/sqlazure/uninstall.sqlazure.utf8.sql</file>
</sql>
</uninstall>
</config>
</extension>


and created the following file structure:

mod_xxx/sql/mysql/install.mysql.utf8.sql & mod_xxx/sql/mysql/install.mysql.utf8.sql

Now he doesn't give me an error while installing, but just won't create my table.
Is my file structure right? Or is the problem in one of my SQL files?

EDIT:

Here is some of MYSQL code

CREATE TABLE IF NOT EXISTS `#__modulename` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`hello` text NOT NULL,
`lang` varchar(25) NOT NULL,

PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;

INSERT INTO `#__modulename` (`hello`, `lang`) VALUES ('Hello World', 'en-GB');
INSERT INTO `#__modulename` (`hello`, `lang`) VALUES ('Hola Mundo', 'es-ES');
INSERT INTO `#__modulename` (`hello`, `lang`) VALUES ('Bonjour tout le monde', 'fr-FR');


My Joomla is currently on a 3.2, I am developing for 3.1.0.

Answer Source

In your XML file further down, you should have something similar to this:

<files>
    <filename module="mod_modulename">mod_modulename.php</filename>
    <filename>index.html</filename>
    <folder>tmpl</folder>
</files>

Make sure you also include <folder>sql</folder>.

As for you SQL code, try the following which is only using 1 insert command. It also tell it which ID to assign the values to which you forgot in your code:

CREATE TABLE IF NOT EXISTS `#__modulename` (
        `id` int(10) NOT NULL AUTO_INCREMENT,
        `hello` text NOT NULL,
        `lang` varchar(25) NOT NULL,

  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;

INSERT INTO `#__modulename` (`id`, `hello`, `lang`) VALUES 
(1, 'Hello World', 'en-GB'),
(2, 'Hola Mundo', 'es-ES'),
(3, 'Bonjour tout le monde', 'fr-FR');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download