Welcome Guest, Not a member yet? Register   Sign In
Create table and fields
#1

[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);
}
#2

[eluser]cybersven[/eluser]
http://ellislab.com/codeigniter/user-gui...forge.html




Theme © iAndrew 2016 - Forum software by © MyBB