Now that Joomla supports multiple database platforms how does an extension check which database the user is deploying on and whether your extension will work with it?

How do create platform specific install/uninstall scripts?


Script file

<!-- Runs on install/uninstall/update; New in 2.5 -->

In script file you can detect used driver:

Joomla 2.5

$app = JFactory::getApplication(); 
$dbtype = $app->getCfg('dbtype');

Joomla 3

$app = JFactory::getApplication(); 
$dbtype = $app->get('dbtype');

Depending on that, execute different code.

Let's say you only support mysql. Detect Joomla! database type on preflight and check if it matches. If not, deny install.

At this point you could conceivably prevent the installation by calling the abort mechanism from the parent or prepare anything ahead of the file copy and database changes occurring.

Source: https://docs.joomla.org/Extension_Installer/Installer_Hooks

 * Called before any type of action
 * @param   string  $route  Which action is happening (install|uninstall|discover_install|update)
 * @param   JAdapterInstance  $adapter  The object responsible for running this script
 * @return  boolean  True on success
public function preflight($route, JAdapterInstance $adapter){
    $app = JFactory::getApplication(); 
    $dbtype = $app->get('dbtype');

    if($dbtype != 'mysql'){
        JError::raiseWarning(null, 'This component dosen\'t support '.$dbtype.' database driver.');

        // Prevent install
        return false;

Install / uninstall SQL files

You can create different files for different database drivers. Notice the driver attribute on file tag.

<install> <!-- Runs on install -->
        <file driver="mysql" charset="utf8">sql/install.mysql.utf8.sql</file>
<uninstall> <!-- Runs on uninstall -->
        <file driver="mysql" charset="utf8">sql/uninstall.mysql.utf8.sql</file>

See Joomla! docs.

Update SQL files

Same on update sql files, you can set type attribute for every schemapath.

<update> <!-- Runs on update; New since J2.5 -->
        <schemapath type="mysql">sql/updates/mysql</schemapath>
        <schemapath type="sqlsrv">sql/updates/sqlsrv</schemapath>

See Joomla! docs.


See supported storage connectors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.