19 January 2021

How to Create table into Database in MySQL in Codeigniter?

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');

}

No comments:

Post a Comment

How to create youtube videos slider with play and pause option in wordpress?

Create youtube videos slider with play and pause option in wordpress youtube videos slider Use this shortcode:- [punjab_today] function my_...