CI_DB_mysqli_forge Class Reference

Inheritance diagram for CI_DB_mysqli_forge:
Collaboration diagram for CI_DB_mysqli_forge:

List of all members.


Public Member Functions

 _create_database ($name)
 Create database.
 _drop_database ($name)
 Drop database.
 _process_fields ($fields)
 Process Fields.
 _create_table ($table, $fields, $primary_keys, $keys, $if_not_exists)
 Create Table.
 _drop_table ($table)
 Drop Table.
 _alter_table ($alter_type, $table, $fields, $after_field= '')
 Alter table query.
 _rename_table ($table_name, $new_table_name)
 Rename a table.

Detailed Description

Definition at line 25 of file mysqli_forge.php.


Member Function Documentation

CI_DB_mysqli_forge::_alter_table ( alter_type,
table,
fields,
after_field = '' 
)

Alter table query.

Generates a platform-specific query so that a table can be altered Called by add_column(), drop_column(), and column_alter(),

private

Parameters:
string the ALTER type (ADD, DROP, CHANGE)
string the column name
array fields
string the field after which we should add the new field
Returns:
object

Definition at line 213 of file mysqli_forge.php.

References CI_DB_forge::$fields, and _process_fields().

00214         {
00215                 $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ";
00216 
00217                 // DROP has everything it needs now.
00218                 if ($alter_type == 'DROP')
00219                 {
00220                         return $sql.$this->db->_protect_identifiers($fields);
00221                 }
00222 
00223                 $sql .= $this->_process_fields($fields);
00224 
00225                 if ($after_field != '')
00226                 {
00227                         $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
00228                 }
00229                 
00230                 return $sql;
00231         }

Here is the call graph for this function:

CI_DB_mysqli_forge::_create_database ( name  ) 

Create database.

private

Parameters:
string the database name
Returns:
bool

Definition at line 34 of file mysqli_forge.php.

00035         {
00036                 return "CREATE DATABASE ".$name;
00037         }

CI_DB_mysqli_forge::_create_table ( table,
fields,
primary_keys,
keys,
if_not_exists 
)

Create Table.

private

Parameters:
string the table name
mixed the fields
mixed primary key(s)
mixed key(s)
boolean should 'IF NOT EXISTS' be added to the SQL
Returns:
bool

Definition at line 141 of file mysqli_forge.php.

References CI_DB_forge::$fields, CI_DB_forge::$keys, CI_DB_forge::$primary_keys, and _process_fields().

00142         {
00143                 $sql = 'CREATE TABLE ';
00144                 
00145                 if ($if_not_exists === TRUE)
00146                 {
00147                         $sql .= 'IF NOT EXISTS ';
00148                 }
00149                 
00150                 $sql .= $this->db->_escape_identifiers($table)." (";
00151 
00152                 $sql .= $this->_process_fields($fields);
00153 
00154                 if (count($primary_keys) > 0)
00155                 {
00156                         $key_name = $this->db->_protect_identifiers(implode('_', $primary_keys));
00157                         $primary_keys = $this->db->_protect_identifiers($primary_keys);
00158                         $sql .= ",\n\tPRIMARY KEY ".$key_name." (" . implode(', ', $primary_keys) . ")";
00159                 }
00160 
00161                 if (is_array($keys) && count($keys) > 0)
00162                 {
00163                         foreach ($keys as $key)
00164                         {
00165                                 if (is_array($key))
00166                                 {
00167                                         $key_name = $this->db->_protect_identifiers(implode('_', $key));
00168                                         $key = $this->db->_protect_identifiers($key);   
00169                                 }
00170                                 else
00171                                 {
00172                                         $key_name = $this->db->_protect_identifiers($key);
00173                                         $key = array($key_name);
00174                                 }
00175                                 
00176                                 $sql .= ",\n\tKEY {$key_name} (" . implode(', ', $key) . ")";
00177                         }
00178                 }
00179 
00180                 $sql .= "\n) DEFAULT CHARACTER SET {$this->db->char_set} COLLATE {$this->db->dbcollat};";
00181 
00182                 return $sql;
00183         }

Here is the call graph for this function:

CI_DB_mysqli_forge::_drop_database ( name  ) 

Drop database.

private

Parameters:
string the database name
Returns:
bool

Definition at line 48 of file mysqli_forge.php.

00049         {
00050                 return "DROP DATABASE ".$name;
00051         }

CI_DB_mysqli_forge::_drop_table ( table  ) 

Drop Table.

private

Returns:
string

Definition at line 193 of file mysqli_forge.php.

00194         {
00195                 return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table);
00196         }

CI_DB_mysqli_forge::_process_fields ( fields  ) 

Process Fields.

private

Parameters:
mixed the fields
Returns:
string

Definition at line 62 of file mysqli_forge.php.

References CI_DB_forge::$fields.

Referenced by _alter_table(), and _create_table().

00063         {
00064                 $current_field_count = 0;
00065                 $sql = '';
00066 
00067                 foreach ($fields as $field=>$attributes)
00068                 {
00069                         // Numeric field names aren't allowed in databases, so if the key is
00070                         // numeric, we know it was assigned by PHP and the developer manually
00071                         // entered the field information, so we'll simply add it to the list
00072                         if (is_numeric($field))
00073                         {
00074                                 $sql .= "\n\t$attributes";
00075                         }
00076                         else
00077                         {
00078                                 $attributes = array_change_key_case($attributes, CASE_UPPER);
00079                                 
00080                                 $sql .= "\n\t".$this->db->_protect_identifiers($field);
00081 
00082                                 if (array_key_exists('NAME', $attributes))
00083                                 {
00084                                         $sql .= ' '.$this->db->_protect_identifiers($attributes['NAME']).' ';
00085                                 }
00086                                 
00087                                 if (array_key_exists('TYPE', $attributes))
00088                                 {
00089                                         $sql .=  ' '.$attributes['TYPE'];
00090                                 }
00091         
00092                                 if (array_key_exists('CONSTRAINT', $attributes))
00093                                 {
00094                                         $sql .= '('.$attributes['CONSTRAINT'].')';
00095                                 }
00096         
00097                                 if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
00098                                 {
00099                                         $sql .= ' UNSIGNED';
00100                                 }
00101         
00102                                 if (array_key_exists('DEFAULT', $attributes))
00103                                 {
00104                                         $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
00105                                 }
00106         
00107                                 if (array_key_exists('NULL', $attributes))
00108                                 {
00109                                         $sql .= ($attributes['NULL'] === TRUE) ? ' NULL' : ' NOT NULL';
00110                                 }
00111         
00112                                 if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
00113                                 {
00114                                         $sql .= ' AUTO_INCREMENT';
00115                                 }
00116                         }
00117                         
00118                         // don't add a comma on the end of the last field
00119                         if (++$current_field_count < count($fields))
00120                         {
00121                                 $sql .= ',';
00122                         }
00123                 }
00124                 
00125                 return $sql;
00126         }

Here is the caller graph for this function:

CI_DB_mysqli_forge::_rename_table ( table_name,
new_table_name 
)

Rename a table.

Generates a platform-specific query so that a table can be renamed

private

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

Definition at line 245 of file mysqli_forge.php.

00246         {
00247                 $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
00248                 return $sql;
00249         }


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