Create table into Database in MySQL in Codeigniter
if ($this->db->table_exists('members'))
{
// table exists some code run query
}
else{
$this->load->dbforge();
// define table fields
$fields = array(
'memid' => array(
'type' => 'INT',
'constraint' => 9,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'firstname' => array(
'type' => 'VARCHAR',
'constraint' => 30
),
'lastname' => array(
'type' => 'VARCHAR',
'constraint' => 30
),
'email' => array(
'type' => 'VARCHAR',
'constraint' => 60,
'unique' => TRUE
),
'password' => array(
'type' => 'VARCHAR',
'constraint' => 40
)
);
$this->dbforge->add_field($fields);
// define primary key
$this->dbforge->add_key('memid', TRUE);
// create table
$this->dbforge->create_table('Members');
}
Comments
Post a Comment