1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Mod installation: Altering Database Tables

Discussion in 'XenForo Development Discussions' started by entertain, Oct 6, 2010.

  1. entertain

    entertain New Member

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

    '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?
  2. vapid

    vapid Member

    This is kind of dirty, and there is probably a better way to do this, but this should work.

    // 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;');
  3. Lawrence

    Lawrence Well-Known Member

    For your on addon, you need an instance of the $db object first:

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

    $db->query('ALTER TABLE .....
    Sniper likes this.

Share This Page