CI_DB_forge Class Reference

Inheritance diagram for CI_DB_forge:

List of all members.


Public Member Functions

 CI_DB_forge ()
 Constructor.
 create_database ($db_name)
 Create database.
 drop_database ($db_name)
 Drop database.
 add_key ($key= '', $primary=FALSE)
 Add Key.
 add_field ($field= '')
 Add Field.
 create_table ($table= '', $if_not_exists=FALSE)
 Create Table.
 drop_table ($table_name)
 Drop Table.
 rename_table ($table_name, $new_table_name)
 Rename Table.
 add_column ($table= '', $field=array(), $after_field= '')
 Column Add.
 drop_column ($table= '', $column_name= '')
 Column Drop.
 modify_column ($table= '', $field=array())
 Column Modify.
 _reset ()
 Reset.

Public Attributes

 $fields = array()
 $keys = array()
 $primary_keys = array()
 $db_char_set = ''

Detailed Description

Definition at line 25 of file DB_forge.php.


Member Function Documentation

CI_DB_forge::_reset (  ) 

Reset.

Resets table creation vars

private

Returns:
void

Definition at line 345 of file DB_forge.php.

Referenced by add_column(), create_table(), and modify_column().

00346         {
00347                 $this->fields           = array();
00348                 $this->keys                     = array();
00349                 $this->primary_keys     = array();
00350         }

Here is the caller graph for this function:

CI_DB_forge::add_column ( table = '',
field = array(),
after_field = '' 
)

Column Add.

public

Parameters:
string the table name
string the column name
string the column definition
Returns:
bool

Definition at line 252 of file DB_forge.php.

References _reset(), add_field(), and show_error().

00253         {
00254                 if ($table == '')
00255                 {
00256                         show_error('A table name is required for that operation.');
00257                 }
00258 
00259                 // add field info into field array, but we can only do one at a time
00260                 // so only grab the first field in the event there are more then one
00261                 $this->add_field(array_slice($field, 0, 1));
00262 
00263                 if (count($this->fields) == 0)
00264                 {       
00265                         show_error('Field information is required.');
00266                 }
00267 
00268                 $sql = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->fields, $after_field);
00269 
00270                 $this->_reset();
00271                 return $this->db->query($sql);
00272         }

Here is the call graph for this function:

CI_DB_forge::add_field ( field = ''  ) 

Add Field.

public

Parameters:
string collation
Returns:
void

Definition at line 134 of file DB_forge.php.

References add_key(), and show_error().

Referenced by add_column(), and modify_column().

00135         {
00136                 if ($field == '')
00137                 {
00138                         show_error('Field information is required.');
00139                 }
00140                 
00141                 if (is_string($field))
00142                 {
00143                         if ($field == 'id')
00144                         {
00145                                 $this->add_field(array(
00146                                                                                 'id' => array(
00147                                                                                                         'type' => 'INT',
00148                                                                                                         'constraint' => 9,
00149                                                                                                         'auto_increment' => TRUE
00150                                                                                                         )
00151                                                                 ));
00152                                 $this->add_key('id', TRUE);
00153                         }
00154                         else
00155                         {
00156                                 if (strpos($field, ' ') === FALSE)
00157                                 {
00158                                         show_error('Field information is required for that operation.');
00159                                 }
00160                                 
00161                                 $this->fields[] = $field;
00162                         }
00163                 }
00164                 
00165                 if (is_array($field))
00166                 {
00167                         $this->fields = array_merge($this->fields, $field);
00168                 }
00169                 
00170         }

Here is the call graph for this function:

Here is the caller graph for this function:

CI_DB_forge::add_key ( key = '',
primary = FALSE 
)

Add Key.

public

Parameters:
string key
string type
Returns:
void

Definition at line 98 of file DB_forge.php.

References show_error().

Referenced by add_field().

00099         {
00100                 if (is_array($key))
00101                 {
00102                         foreach($key as $one)
00103                         {
00104                                 $this->add_key($one, $primary);
00105                         }
00106                         
00107                         return;
00108                 }
00109         
00110                 if ($key == '')
00111                 {
00112                         show_error('Key information is required for that operation.');
00113                 }
00114                 
00115                 if ($primary === TRUE)
00116                 {
00117                         $this->primary_keys[] = $key;
00118                 }
00119                 else
00120                 {
00121                         $this->keys[] = $key;
00122                 }
00123         }

Here is the call graph for this function:

Here is the caller graph for this function:

CI_DB_forge::CI_DB_forge (  ) 

Constructor.

Grabs the CI super object instance so we can access it.

Definition at line 38 of file DB_forge.php.

References $CI, get_instance(), and log_message().

00039         {
00040                 // Assign the main database object to $this->db
00041                 $CI =& get_instance();
00042                 $this->db =& $CI->db;
00043                 log_message('debug', "Database Forge Class Initialized");
00044         }

Here is the call graph for this function:

CI_DB_forge::create_database ( db_name  ) 

Create database.

public

Parameters:
string the database name
Returns:
bool

Definition at line 55 of file DB_forge.php.

00056         {
00057                 $sql = $this->_create_database($db_name);
00058                 
00059                 if (is_bool($sql))
00060                 {
00061                         return $sql;
00062                 }
00063         
00064                 return $this->db->query($sql);
00065         }

CI_DB_forge::create_table ( table = '',
if_not_exists = FALSE 
)

Create Table.

public

Parameters:
string the table name
Returns:
bool

Definition at line 181 of file DB_forge.php.

References _reset(), and show_error().

00182         {       
00183                 if ($table == '')
00184                 {
00185                         show_error('A table name is required for that operation.');
00186                 }
00187                         
00188                 if (count($this->fields) == 0)
00189                 {       
00190                         show_error('Field information is required.');
00191                 }
00192 
00193                 $sql = $this->_create_table($this->db->dbprefix.$table, $this->fields, $this->primary_keys, $this->keys, $if_not_exists);
00194                 
00195                 $this->_reset();
00196                 return $this->db->query($sql);
00197         }

Here is the call graph for this function:

CI_DB_forge::drop_column ( table = '',
column_name = '' 
)

Column Drop.

public

Parameters:
string the table name
string the column name
Returns:
bool

Definition at line 284 of file DB_forge.php.

References show_error().

00285         {
00286         
00287                 if ($table == '')
00288                 {
00289                         show_error('A table name is required for that operation.');
00290                 }
00291 
00292                 if ($column_name == '')
00293                 {
00294                         show_error('A column name is required for that operation.');
00295                 }
00296 
00297                 $sql = $this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name);
00298         
00299                 return $this->db->query($sql);
00300         }

Here is the call graph for this function:

CI_DB_forge::drop_database ( db_name  ) 

Drop database.

public

Parameters:
string the database name
Returns:
bool

Definition at line 76 of file DB_forge.php.

00077         {
00078                 $sql = $this->_drop_database($db_name);
00079                 
00080                 if (is_bool($sql))
00081                 {
00082                         return $sql;
00083                 }
00084         
00085                 return $this->db->query($sql);
00086         }

CI_DB_forge::drop_table ( table_name  ) 

Drop Table.

public

Parameters:
string the table name
Returns:
bool

Definition at line 208 of file DB_forge.php.

00209         {
00210                 $sql = $this->_drop_table($this->db->dbprefix.$table_name);
00211                 
00212                 if (is_bool($sql))
00213                 {
00214                         return $sql;
00215                 }
00216         
00217                 return $this->db->query($sql);
00218         }

CI_DB_forge::modify_column ( table = '',
field = array() 
)

Column Modify.

public

Parameters:
string the table name
string the column name
string the column definition
Returns:
bool

Definition at line 313 of file DB_forge.php.

References _reset(), add_field(), and show_error().

00314         {
00315                 if ($table == '')
00316                 {
00317                         show_error('A table name is required for that operation.');
00318                 }
00319 
00320                 // add field info into field array, but we can only do one at a time
00321                 // so only grab the first field in the event there are more then one
00322                 $this->add_field(array_slice($field, 0, 1));
00323 
00324                 if (count($this->fields) == 0)
00325                 {       
00326                         show_error('Field information is required.');
00327                 }
00328 
00329                 $sql = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->fields);
00330 
00331                 $this->_reset();
00332                 return $this->db->query($sql);
00333         }

Here is the call graph for this function:

CI_DB_forge::rename_table ( table_name,
new_table_name 
)

Rename Table.

public

Parameters:
string the old table name
string the new table name
Returns:
bool

Definition at line 230 of file DB_forge.php.

References show_error().

00231         {
00232                 if ($table_name == '' OR $new_table_name == '')
00233                 {
00234                         show_error('A table name is required for that operation.');
00235                 }
00236                         
00237                 $sql = $this->_rename_table($table_name, $new_table_name);
00238                 return $this->db->query($sql);
00239         }

Here is the call graph for this function:


Member Data Documentation

CI_DB_forge::$db_char_set = ''

Definition at line 30 of file DB_forge.php.


The documentation for this class was generated from the following file: