db_add_column From Online Manual

Revision as of 21:45, 8 October 2012 by Emanuele (talk | contribs)
Jump to: navigation, search

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: