mysql – Initialization of table in database using ‘CREATE … IF NOT EXISTS’
Question
Proceeding first plugin installation and activation, I’ve initialized a table in database for plugin-related data using the statement ‘CREATE … IF NOT EXISTS’ :
$init_query = 'CREATE TABLE IF NOT EXISTS `' . $this->db_prefix . $table_name . '` ' . $table;
$init_query .= ' ' . $this->db_charset_collate();
$prepare_init_query = $this->db->prepare( $init_query );
$run_init_query = execute_query( $prepare_init_query );
Would this be the ideal way to go about initializing a table registering the plugin activation hook with class containing the code above or is it better to just use query condition like:
if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
in terms of overhead.
0
1 month
2022-12-19T04:46:08-05:00
2022-12-19T04:46:08-05:00 0 Answers
0 views
0
Leave an answer