Db add column: Difference between revisions From Online Manual

Jump to: navigation, search
(Created page with "{{smcfunc |function=db_add_column |usage=$smcFunc['db_add_column'] (table_name, column_info, parameters, if_exists, error) |description=This function is used to add a new column...")
 
mNo edit summary
Line 1: Line 1:
{{smcfunc
{{smcfunc
|function=db_add_column
|function=db_add_column
|usage=$smcFunc['db_add_column'] (table_name, column_info, parameters, if_exists, error)  
|usage=$smcFunc['db_add_column'](table_name, column_info, parameters, if_exists, error)  
|description=This function is used to add a new column to an existing table.
|description=This function is used to add a new column to an existing table.
|parameters={{parmdesc
|parameters={{parmdesc

Revision as of 13:31, 21 October 2011

Usage:

$smcFunc['db_add_column'](table_name, column_info, parameters, if_exists, error)


Description: This function is used to add a new column to an existing table.

Parameters:

  • table_name (string) the name of an existing table
  • column_info (array) an array of data containing the following keys:
    • name (string) the name of the column
    • type (string) the type of the column (e.g. int, tinyint, varchar, text, etc.)
    • size (integer) defines the size of the column (if required by type)
    • null (boolean) whether to use null or not null
    • default (integer) or string depending on type) should contain the default value for the column
    • auto (boolean) whether the column uses auto_increment or not
    • unsigned (boolean) specifies whether the column is unsigned or not (applicable only to MySQL).
  • parameters (array) none, leave empty
  • if_exists (string) controls what to do if the column exists, default update (updates the column), any other value will result in non creating the column
  • error (string) what to do if an error was encountered, default fatal

Example:

$smcFunc['db_add_column'](
	'{db_prefix}spiders',
	array(
		'name' => 'temp_order',
		'size' => 8,
		'type' => 'mediumint',
		'null' => false
	)
);



Advertisement: