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 336 of file DB_forge.php.

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

00337         {
00338                 $this->fields           = array();
00339                 $this->keys                     = array();
00340                 $this->primary_keys     = array();
00341         }

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 242 of file DB_forge.php.

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

00243         {
00244                 if ($table == '')
00245                 {
00246                                 show_error('A table name is required for that operation.');
00247                 }
00248 
00249                 // add field info into field array, but we can only do one at a time
00250                 // so only grab the first field in the event there are more then one
00251                 $this->add_field(array_slice($field, 0, 1));
00252 
00253                 if (count($this->fields) == 0)
00254                 {       
00255                         show_error('Field information is required.');
00256                 }
00257 
00258                 $sql = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->fields, $after_field);
00259 
00260                 $this->_reset();
00261                 return $this->db->query($sql);
00262         }

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 124 of file DB_forge.php.

References add_key(), and show_error().

Referenced by add_column(), and modify_column().

00125         {
00126                 if ($field == '')
00127                 {
00128                         show_error('Field information is required.');
00129                 }
00130                 
00131                 if (is_string($field))
00132                 {
00133                         if ($field == 'id')
00134                         {
00135                                 $this->add_field(array(
00136                                                                                 'id' => array(
00137                                                                                                         'type' => 'INT',
00138                                                                                                         'constraint' => 9,
00139                                                                                                         'auto_increment' => TRUE
00140                                                                                                         )
00141                                                                 ));
00142                                 $this->add_key('id', TRUE);
00143                         }
00144                         else
00145                         {
00146                                 if (strpos($field, ' ') === FALSE)
00147                                 {
00148                                         show_error('Field information is required for that operation.');
00149                                 }
00150                                 
00151                                 $this->fields[] = $field;
00152                         }
00153                 }
00154                 
00155                 if (is_array($field))
00156                 {
00157                         $this->fields = array_merge($this->fields, $field);
00158                 }
00159                 
00160         }

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 ($key == '')
00101                 {
00102                         show_error('Key information is required for that operation.');
00103                 }
00104                 
00105                 if ($primary === TRUE)
00106                 {
00107                         $this->primary_keys[] = $key;
00108                 }
00109                 else
00110                 {
00111                         $this->keys[] = $key;
00112                 }
00113         }

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 171 of file DB_forge.php.

References _reset(), and show_error().

00172         {       
00173                 if ($table == '')
00174                 {
00175                         show_error('A table name is required for that operation.');
00176                 }
00177                         
00178                 if (count($this->fields) == 0)
00179                 {       
00180                         show_error('Field information is required.');
00181                 }
00182 
00183                 $sql = $this->_create_table($this->db->dbprefix.$table, $this->fields, $this->primary_keys, $this->keys, $if_not_exists);
00184 
00185                 $this->_reset();
00186                 return $this->db->query($sql);
00187         }

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 274 of file DB_forge.php.

References show_error().

00275         {
00276         
00277                 if ($table == '')
00278                 {
00279                                 show_error('A table name is required for that operation.');
00280                 }
00281 
00282                 if ($column_name == '')
00283                 {
00284                                 show_error('A column name is required for that operation.');
00285                 }
00286 
00287                 $sql = $this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name);
00288         
00289                 return $this->db->query($sql);
00290         }

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 198 of file DB_forge.php.

00199         {
00200                 $sql = $this->_drop_table($this->db->dbprefix.$table_name);
00201                 
00202                 if (is_bool($sql))
00203                 {
00204                         return $sql;
00205                 }
00206         
00207                 return $this->db->query($sql);
00208         }

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 303 of file DB_forge.php.

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

00304         {
00305         
00306                 if ($table == '')
00307                 {
00308                                 show_error('A table name is required for that operation.');
00309                 }
00310 
00311                 // add field info into field array, but we can only do one at a time
00312                 // so only grab the first field in the event there are more then one
00313                 $this->add_field(array_slice($field, 0, 1));
00314 
00315                 if (count($this->fields) == 0)
00316                 {       
00317                         show_error('Field information is required.');
00318                 }
00319 
00320                 $sql = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->fields);
00321 
00322                 $this->_reset();
00323                 return $this->db->query($sql);
00324         }

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 220 of file DB_forge.php.

References show_error().

00221         {
00222                 if ($table_name == '' OR $new_table_name == '')
00223                 {
00224                         show_error('A table name is required for that operation.');
00225                 }
00226                         
00227                 $sql = $this->_rename_table($table_name, $new_table_name);
00228                 return $this->db->query($sql);
00229         }

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: