Monday, December 19, 2022
HomeWordPress Developmentmysql - Initialization of desk in database utilizing 'CREATE ... IF NOT...

mysql – Initialization of desk in database utilizing ‘CREATE … IF NOT EXISTS’


Continuing first plugin set up and activation, I’ve initialized a desk in database for plugin-related knowledge utilizing the assertion ‘CREATE … IF NOT EXISTS’ :

$init_query = 'CREATE TABLE IF NOT EXISTS `' . $this->db_prefix . $table_name . '` ' . $desk;
$init_query .= ' ' . $this->db_charset_collate();
$prepare_init_query = $this->db->put together( $init_query );
$run_init_query = execute_query( $prepare_init_query );

Would this be the best technique to go about initializing a desk registering the plugin activation hook with class containing the code above or is it higher to only use question situation like:

if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {

when it comes to overhead.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments