Mod installation: Altering Database Tables

entertain

New member
In vBulletin I was used to alter database tables like this:

PHP:
        $dbalter->fetch_table_info('tablename');
         $dbalter->add_field(array(
            'name'       => 'fieldname',
            'type'       => 'int',
            'length'       => '10',
            'null'       => false,
            'default'    => '0'
        ), false);
But this commands are not working anymore. How do they have to look like?
 
This is kind of dirty, and there is probably a better way to do this, but this should work.

PHP:
// to add a column to a table
$db->query('ALTER TABLE the_table ADD COLUMN randomCol INT(10) NOT NULL DEFAULT 0;');

// to remove a column from a table
$db->query('ALTER TABLE the_table DROP COLUMN randomCol;');
 
For your on addon, you need an instance of the $db object first:

$db = XenForo_Application::get('db');

$db->query('ALTER TABLE .....
 
Top Bottom