简体   繁体   English

Joomla扩展更新-将列添加到数据库表

[英]Joomla extension update - add column to database table

I have read the Joomla Documentation regarding running SQL files upon extension updates, however the problem being is that the previous version of our extension doesn't have the SQL files therefore this method cannot be used. 我已经阅读了有关在扩展程序更新时运行SQL文件的Joomla文档 ,但是问题是我们的扩展程序的先前版本没有SQL文件,因此无法使用此方法。

I am pretty sure running an SQL command in the installscript.php can be done, so I tried adding the query to the update function like so: 我很确定可以在installscript.php中运行SQL命令,因此我尝试将查询添加到更新函数中,如下所示:

function update( $parent ) {

    echo '<p>' . JText::_('MOD_SHOUTBOX_UPDATE') . $this->release . '</p>';

    $db = JFactory::getDBO();
    $sql = "ALTER TABLE #__shoutbox ADD COLUMN user_id int(11) NOT NULL DEFAULT '0'";
    $db->setQuery($sql);
}

The query works fine if it's added via PHPMyAdmin and I have also turned on System debugging but the query doesn't appear in the list. 如果查询是通过PHPMyAdmin添加的,则该查询工作正常,而且我还打开了系统调试功能,但该查询未出现在列表中。

Does anyone know where I'm going wrong? 有谁知道我要去哪里错了?

If you are sure that update function is called than the only reason it's not working is you are missing query function. 如果您确定调用了update函数,而不是它不起作用的唯一原因是您缺少query函数。

Add this line 添加此行

$result = $db->query();

after

$db->setQuery($sql);

Hope this will help. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM