joomla 2.5 in module install.mysql.utf8.sql dosent work

拥有回忆 提交于 2019-12-12 14:41:58

问题


i want to install extranal sql file with module and i follow this link tutorial http://docs.joomla.org/J2.5:Creating_a_simple_module/Using_the_Database but it dose not work. here is my xml and sql file coding. where is my mistake?

<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="2.5.0" client="site" method="upgrade">
<name>practic_module</name>
<author>John Doe</author>
<version>1.0.0</version>
<description>this is a practice module struckture</description>
<files>
<filename>mod_helloworld.xml</filename>
<filename module="mod_helloworld">mod_helloworld.php</filename>
<filename>index.html</filename>
<filename>helper.php</filename>
<filename>tmpl/default.php</filename>
<filename>tmpl/index.html</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>

<update> 
<schemas>
    <schemapath type="mysql">sql/mysql/updates</schemapath> 
    <schemapath type="sqlazure">sql/sqlazure/updates</schemapath> 
</schemas> 
</update>

<fields name="params">
<fieldset name="basic">
    <field name="lang" type="sql" default="1" label="Select a language" query="SELECT id AS value, lang FROM #__helloworld" />
</fieldset>
</fields>


</config>

</extension>

and sql directory is C:\xampp\htdocs\joom\modules\mod_helloworld\sql\mysql and install.mysql.utf8.sql file is

CREATE TABLE IF NOT EXISTS `#__helloworld` (
    `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 `#__helloworld` (`hello`, `lang`) VALUES ('Hello World', 'en-GB');
INSERT INTO `#__helloworld` (`hello`, `lang`) VALUES ('Hola Mundo', 'es-ES');
INSERT INTO `#__helloworld` (`hello`, `lang`) VALUES ('Bonjour tout le monde', 'fr-  FR');  

but it dose not work. database not install. where my mistake? pls help


回答1:


You have added the <install>, <uninstall> and <update> tags inside the <config> tags which shouldn't be done. They need to go outside. You also need to define the sql folder. Here is your full xml code:

<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="2.5.0" client="site" method="upgrade">
<name>practic_module</name>
<author>John Doe</author>
<version>1.0.0</version>
<description>this is a practice module struckture</description>

<files>
   <filename>mod_helloworld.xml</filename>
   <filename module="mod_helloworld">mod_helloworld.php</filename>
   <filename>index.html</filename>
   <filename>helper.php</filename>
   <filename>tmpl/default.php</filename>
   <filename>tmpl/index.html</filename>
   <folder>sql</folder>
</files>

<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>

<update> 
<schemas>
    <schemapath type="mysql">sql/mysql/updates</schemapath> 
    <schemapath type="sqlazure">sql/sqlazure/updates</schemapath> 
</schemas> 
</update>

<config>
   <fields name="params">
      <fieldset name="basic">
         <field name="lang" type="sql" default="1" label="Select a language" query="SELECT id AS value, lang FROM #__helloworld" />
      </fieldset>
   </fields>
</config>

</extension>

Also make sure you folder structure is correct

Hope this helps




回答2:


I think you should use config tag just around

<fields name="params">
  <fieldset name="basic">
  <field name="lang" type="sql" default="1" label="Select a language" query="SELECT id AS value, lang FROM        #__helloworld" />
  </fieldset>
</fields>



回答3:


in your uploaded zip, in the manifest file is no <folder>sql</folder> - so the installer dont copy the folder on install into the module directory and dont execute the sql.

installer: https://github.com/joomla/joomla-cms/blob/master/libraries/cms/installer/installer.php#L912




回答4:


You need to include these files in files tag, like this:

<files>
    <!-- The others files that you added -->
    <filename>sql/mysql/install.mysql.utf8.sql</filename>
    <filename>sql/sqlazure/install.sqlazure.utf8.sql</filename>
    <filename>sql/mysql/uninstall.mysql.utf8.sql</filename>
    <filename>sql/sqlazure/uninstall.sqlazure.utf8.sql</filename>
    <filename>sql/sqlazure/updates</filename> <!-- Not sure about this one, sorry -->
</file>

I'm learning too and i don't know if the updates file is necessary to add on files tag. Combine this with Lodder's answer. Hope be useful.



来源:https://stackoverflow.com/questions/20219465/joomla-2-5-in-module-install-mysql-utf8-sql-dosent-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!