CodeIgniter Forums

Full Version: Create table and fields
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]maddtechwf[/eluser]
I've written a small line of code that checks to see if my database exists. I checked it and it is working fine. What I'm having issues with is the code to create the table and fields if it doesn't exists. Can anyone help me with this?

Check if table exists:
Code:
$dbtemp = $this->db->table_exists('my_table');

if($dbtemp == FALSE)
{
     create_my_table();
}

This is what my function to create the table looks like:
Code:
public function create_my_table()
{
     $fields = arrary(
            'id'  = array(
                     'type'    =>  'INT',
                     'unsigned' => TRUE,
                     'auto_increment' => TRUE
             ),
             'test' = array(
                     'type' => 'VARCHAR',
                     'constraint' => '255'
              ),
      );
      $this->dbforge->add_field($fields);
  
      $this->dbforge->create_table('my_table', TRUE);
}

El Forum