Umil.table add

From phpBB Development Wiki

umil::table_add –– Add a database table using the Umil Library.

Contents

Description

string umil::table_add ( mixed $table_name [, array $table_data ] )

Parameters

Parameter Required/Default Usage
table_name Required The name of the database table to add. You may just use phpbb_ for the table prefix if you would like. UMIL correctly sets the table prefix to the board's default if you enter in phpbb_
table_data default array() The array of table data we will create the new database table with

Return Values

Returns result or umil_end data

This article is a stub. You can help in improving Olympus Documentation by expanding it.


Table Data

The table data is an array of information pertaining to how Umil will create the table.

There are 3 sections to it, COLUMNS, PRIMARY_KEY, and KEYS.

Columns

Information for setting up the columns are here. This should be given as an array with the column name being the array key and the value being an array with the data.

In the value array holding the information, the first item is the Database_Type_Map, the second item is the default value, and the third item is optional and to be used for special fields.

For example, setting up an auto increment column:

'user_id'    => array('UINT'NULL'auto_increment')

Or a description field, say for the forum description:

'forum_desc'    => array('TEXT_UNI'''),

Primary Key

The primary key is where you would enter what the primary key for the table is.

For example, user_id:

'user_id'

Having the primary key be multiple columns (in this case, role_id and role_option_id):

array('role_id''auth_option_id')

Keys

The extra keys/indexes for the table

For example, an index named module_enabled for the module_enabled column:

'module_enabled'    => array('INDEX''module_enabled'),

Or an index named left_right_id for the left_id and right_id columns:

'left_right_id'    => array('INDEX', array('left_id''right_id')),

Examples

Example #1

The phpbb_icons table.

$umil->table_add('phpbb_icons', array(
    
'COLUMNS'        => array(
        
'icons_id'                => array('UINT'NULL'auto_increment'),
        
'icons_url'                => array('VCHAR'''),
        
'icons_width'            => array('TINT:4'0),
        
'icons_height'            => array('TINT:4'0),
        
'icons_order'            => array('UINT'0),
        
'display_on_posting'    => array('BOOL'1),
    ),
    
'PRIMARY_KEY'    => 'icons_id',
    
'KEYS'            => array(
        
'display_on_posting'    => array('INDEX''display_on_posting'),
    ),
));

Example #2

The posts table

$umil->table_add(POSTS_TABLE, array(
    
'COLUMNS'        => array(
        
'post_id'                => array('UINT'NULL'auto_increment'),
        
'topic_id'                => array('UINT'0),
        
'forum_id'                => array('UINT'0),
        
'poster_id'                => array('UINT'0),
        
'icon_id'                => array('UINT'0),
        
'poster_ip'                => array('VCHAR:40'''),
        
'post_time'                => array('TIMESTAMP'0),
        
'post_approved'            => array('BOOL'1),
        
'post_reported'            => array('BOOL'0),
        
'enable_bbcode'            => array('BOOL'1),
        
'enable_smilies'        => array('BOOL'1),
        
'enable_magic_url'        => array('BOOL'1),
        
'enable_sig'            => array('BOOL'1),
        
'post_username'            => array('VCHAR_UNI:255'''),
        
'post_subject'            => array('STEXT_UNI''''true_sort'),
        
'post_text'                => array('MTEXT_UNI'''),
        
'post_checksum'            => array('VCHAR:32'''),
        
'post_attachment'        => array('BOOL'0),
        
'bbcode_bitfield'        => array('VCHAR:255'''),
        
'bbcode_uid'            => array('VCHAR:8'''),
        
'post_postcount'        => array('BOOL'1),
        
'post_edit_time'        => array('TIMESTAMP'0),
        
'post_edit_reason'        => array('STEXT_UNI'''),
        
'post_edit_user'        => array('UINT'0),
        
'post_edit_count'        => array('USINT'0),
        
'post_edit_locked'        => array('BOOL'0),
    ),
    
'PRIMARY_KEY'    => 'post_id',
    
'KEYS'            => array(
        
'forum_id'                => array('INDEX''forum_id'),
        
'topic_id'                => array('INDEX''topic_id'),
        
'poster_ip'                => array('INDEX''poster_ip'),
        
'poster_id'                => array('INDEX''poster_id'),
        
'post_approved'            => array('INDEX''post_approved'),
        
'tid_post_time'            => array('INDEX', array('topic_id''post_time')),
    ),
));

Example #3

Adding multiple tables with one function call

$umil->table_add(array(
    array(
'phpbb_poll_options', array(
        
'COLUMNS'        => array(
            
'poll_option_id'        => array('TINT:4'0),
            
'topic_id'                => array('UINT'0),
            
'poll_option_text'        => array('TEXT_UNI'''),
            
'poll_option_total'        => array('UINT'0),
        ),
        
'KEYS'            => array(
            
'poll_opt_id'            => array('INDEX''poll_option_id'),
            
'topic_id'                => array('INDEX''topic_id'),
        ),
    )),
    array(
'phpbb_poll_votes', array(
        
'COLUMNS'        => array(
            
'topic_id'                => array('UINT'0),
            
'poll_option_id'        => array('TINT:4'0),
            
'vote_user_id'            => array('UINT'0),
            
'vote_user_ip'            => array('VCHAR:40'''),
        ),
        
'KEYS'            => array(
            
'topic_id'                => array('INDEX''topic_id'),
            
'vote_user_id'            => array('INDEX''vote_user_id'),
            
'vote_user_ip'            => array('INDEX''vote_user_ip'),
        ),
    )),
));


See Also