smf_db_add_column

Description

Adds a column to a table

Syntax

bool smf_db_add_column (string $table_name, array $column_info[, array $parameters[, string $if_exists[, string $error]]])



Parameter $table_name

Expected type: String
Description: The name of the table to add the column to.



Parameter $column_info

Expected type: Array
Description: An array of information about the column that we want to add

Array Elements of $column_info
Key Optional Expected type Description
name no String The name of the column
type no Enumerated String The type of column - can be smallint,mediumint,int,text,varchar,char,tinytext,mediumtext,largetext
auto yes Mixed Set to true to make it an auto incrementing column. Set to a numerical value to set from what it should begin counting.
default yes Mixed Default value - do not set if no default required.
null yes Boolean Can it be null (true or false) - if not set default will be false.
size yes Integer Size of column (If applicable) - for example 255 for a large varchar, 10 for an int etc. If not set SMF will pick a size.



Parameter $parameters

Expected type: Array
Description: An array of parameters

Array Elements of $parameters
Key Optional Expected type Description
no_prefix yes Boolean If true, SMF won't add the db prefix to the table.



Parameter $if_exists

Expected type: Enumerated String
Description: What to do if the column already exists

Possible string values
Allowed values Description
'update' Update the existing column to match the type, options, etc.



Parameter $error

Expected type: Enumerated String
Description: Error parameter

Possible string values
Allowed values Description
'fatal' Fatal error



Return value

Expected type: Boolean
Description: Returns true if the column was successfully added or updated, false otherwise


Notes

  • If the column already exists, and $if_exists is "update", updates the existing column to match the specifications
Advertisement: