简体   繁体   中英

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.

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:

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.

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.

Add this line

$result = $db->query();

after

$db->setQuery($sql);

Hope this will help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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