Skip to content

CI_DB_forge

Mathieu Nayrolles edited this page Jan 20, 2016 · 1 revision

CI_DB_forge

Database Forge Class

  • Class name: CI_DB_forge
  • Namespace:
  • This is an abstract class

Properties

$db

protected object $db

Database object

  • Visibility: protected

$fields

public array $fields = array()

Fields data

  • Visibility: public

$keys

public array $keys = array()

Keys data

  • Visibility: public

$primary_keys

public array $primary_keys = array()

Primary Keys data

  • Visibility: public

$db_char_set

public string $db_char_set = ''

Database character set

  • Visibility: public

$_create_database

protected string $_create_database = 'CREATE DATABASE %s'

CREATE DATABASE statement

  • Visibility: protected

$_drop_database

protected string $_drop_database = 'DROP DATABASE %s'

DROP DATABASE statement

  • Visibility: protected

$_create_table

protected string $_create_table = "%s %s (%s\n)"

CREATE TABLE statement

  • Visibility: protected

$_create_table_if

protected string $_create_table_if = 'CREATE TABLE IF NOT EXISTS'

CREATE TABLE IF statement

  • Visibility: protected

$_create_table_keys

protected boolean $_create_table_keys = FALSE

CREATE TABLE keys flag

Whether table keys are created from within the CREATE TABLE statement.

  • Visibility: protected

$_drop_table_if

protected string $_drop_table_if = 'DROP TABLE IF EXISTS'

DROP TABLE IF EXISTS statement

  • Visibility: protected

$_rename_table

protected string $_rename_table = 'ALTER TABLE %s RENAME TO %s;'

RENAME TABLE statement

  • Visibility: protected

$_unsigned

protected boolean $_unsigned = TRUE

UNSIGNED support

  • Visibility: protected

$_null

protected string $_null = ''

NULL value representation in CREATE/ALTER TABLE statements

  • Visibility: protected

$_default

protected string $_default = ' DEFAULT '

DEFAULT value representation in CREATE/ALTER TABLE statements

  • Visibility: protected

Methods

__construct

void CI_DB_forge::__construct($db)

Class constructor

  • Visibility: public

Arguments

  • $db mixed

create_database

boolean CI_DB_forge::create_database(string $db_name)

Create database

  • Visibility: public

Arguments

  • $db_name string

drop_database

boolean CI_DB_forge::drop_database(string $db_name)

Drop database

  • Visibility: public

Arguments

  • $db_name string

add_key

\CI_DB_forge CI_DB_forge::add_key(string $key, boolean $primary)

Add Key

  • Visibility: public

Arguments

  • $key string
  • $primary boolean

add_field

\CI_DB_forge CI_DB_forge::add_field(array $field)

Add Field

  • Visibility: public

Arguments

  • $field array

create_table

boolean CI_DB_forge::create_table(string $table, boolean $if_not_exists, array $attributes)

Create Table

  • Visibility: public

Arguments

  • $table string - <p>Table name</p>
  • $if_not_exists boolean - <p>Whether to add IF NOT EXISTS condition</p>
  • $attributes array - <p>Associative array of table attributes</p>

_create_table

mixed CI_DB_forge::_create_table(string $table, boolean $if_not_exists, array $attributes)

Create Table

  • Visibility: protected

Arguments

  • $table string - <p>Table name</p>
  • $if_not_exists boolean - <p>Whether to add 'IF NOT EXISTS' condition</p>
  • $attributes array - <p>Associative array of table attributes</p>

_create_table_attr

string CI_DB_forge::_create_table_attr(array $attributes)

CREATE TABLE attributes

  • Visibility: protected

Arguments

  • $attributes array - <p>Associative array of table attributes</p>

drop_table

boolean CI_DB_forge::drop_table(string $table_name, boolean $if_exists)

Drop Table

  • Visibility: public

Arguments

  • $table_name string - <p>Table name</p>
  • $if_exists boolean - <p>Whether to add an IF EXISTS condition</p>

_drop_table

string CI_DB_forge::_drop_table(string $table, boolean $if_exists)

Drop Table

Generates a platform-specific DROP TABLE string

  • Visibility: protected

Arguments

  • $table string - <p>Table name</p>
  • $if_exists boolean - <p>Whether to add an IF EXISTS condition</p>

rename_table

boolean CI_DB_forge::rename_table(string $table_name, string $new_table_name)

Rename Table

  • Visibility: public

Arguments

  • $table_name string - <p>Old table name</p>
  • $new_table_name string - <p>New table name</p>

add_column

boolean CI_DB_forge::add_column(string $table, array $field, string $_after)

Column Add

  • Visibility: public

Arguments

  • $table string - <p>Table name</p>
  • $field array - <p>Column definition</p>
  • $_after string - <p>Column for AFTER clause (deprecated)</p>

drop_column

boolean CI_DB_forge::drop_column(string $table, string $column_name)

Column Drop

  • Visibility: public

Arguments

  • $table string - <p>Table name</p>
  • $column_name string - <p>Column name</p>

modify_column

boolean CI_DB_forge::modify_column(string $table, string $field)

Column Modify

  • Visibility: public

Arguments

  • $table string - <p>Table name</p>
  • $field string - <p>Column definition</p>

_alter_table

string|array<mixed,string> CI_DB_forge::_alter_table(string $alter_type, string $table, mixed $field)

ALTER TABLE

  • Visibility: protected

Arguments

  • $alter_type string - <p>ALTER type</p>
  • $table string - <p>Table name</p>
  • $field mixed - <p>Column definition</p>

_process_fields

array CI_DB_forge::_process_fields(boolean $create_table)

Process fields

  • Visibility: protected

Arguments

  • $create_table boolean

_process_column

string CI_DB_forge::_process_column(array $field)

Process column

  • Visibility: protected

Arguments

  • $field array

_attr_type

void CI_DB_forge::_attr_type($attributes)

Field attribute TYPE

Performs a data type mapping between different databases.

  • Visibility: protected

Arguments

  • $attributes mixed

_attr_unsigned

void CI_DB_forge::_attr_unsigned($attributes, $field)

Field attribute UNSIGNED

Depending on the _unsigned property value:

  • TRUE will always set $field['unsigned'] to 'UNSIGNED'
  • FALSE will always set $field['unsigned'] to ''
  • array(TYPE) will set $field['unsigned'] to 'UNSIGNED', if $attributes['TYPE'] is found in the array
  • array(TYPE => UTYPE) will change $field['type'], from TYPE to UTYPE in case of a match
  • Visibility: protected

Arguments

  • $attributes mixed
  • $field mixed

_attr_default

void CI_DB_forge::_attr_default($attributes, $field)

Field attribute DEFAULT

  • Visibility: protected

Arguments

  • $attributes mixed
  • $field mixed

_attr_unique

void CI_DB_forge::_attr_unique($attributes, $field)

Field attribute UNIQUE

  • Visibility: protected

Arguments

  • $attributes mixed
  • $field mixed

_attr_auto_increment

void CI_DB_forge::_attr_auto_increment($attributes, $field)

Field attribute AUTO_INCREMENT

  • Visibility: protected

Arguments

  • $attributes mixed
  • $field mixed

_process_primary_keys

string CI_DB_forge::_process_primary_keys(string $table)

Process primary keys

  • Visibility: protected

Arguments

  • $table string - <p>Table name</p>

_process_indexes

string CI_DB_forge::_process_indexes(string $table)

Process indexes

  • Visibility: protected

Arguments

  • $table string

_reset

void CI_DB_forge::_reset()

Reset

Resets table creation vars

  • Visibility: protected
Clone this wiki locally