How to check if a mysql database table already exists with codeigniter4?

Asked

Viewed 76 times

0

How to check if a certain Mysql database table already exists with codeigniter 4, and if it does not exist, create this table ?

1 answer

1


You can make a query to see if the table really exists, example:

if ($this->db->table_exists($table) )
{
  // table exists some code run query
}
else
{
  // table does not exist
}

And to create a table you can use this excerpt (it already does a validation to see if there is or not the table in question).

$this->dbforge->create_table('table_name', TRUE);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.