与Postgres兼容的Joomla-Components

时间:2012-06-23 10:00:04

标签: php postgresql joomla

由于Joomla 2.5原生支持PostgreSQL,我们非常支持那个。在我为系统开发组件时,我想知道使它兼容的确切语义是什么?

对于MySQL,我在admin/sql/install.mysql.utf8.sql中安装了我的安装脚本。 PostgreSQL会是什么?我也可以使用#_作为数据库前缀吗?

1 个答案:

答案 0 :(得分:3)

额外的数据库支持应尽可能透明,以便您可以保持大部分代码相同。

如果您一直在使用Joomla!的JDatabase类,那么您应该在PHP中构建这样的查询:

    /* (example php may not actually work)
       Get the factory DB object */
    $db = JFactory::getDbo();
    // Get a new JDatabaseQuery object
    $query = $db->getQuery(true);
    // Build our query...
    $query->select('id');
    $query->from('#__mycomponents_table');
    $query->where('id=99');
    // Attach the query to the DB object
    $db->setQuery($query);
    // Run it and check the result...
    if (!$db->loadResult()){...}

正如您所知,安装/卸载SQL脚本之类的东西需要特定于数据库。这意味着对清单XML的一个小更新......这是一个例子。

<install>
    <sql>
        <file charset="utf8" driver="mysql">sql/install.mysql.sql</file>
        <file charset="utf8" driver="postgresql">sql/install.postgresql.sql</file>
    </sql>
</install>

我建议查看com_finder代码,因为它有一个Postgres安装/卸载SQL的具体示例。