Storing database table name as const

[ad_1]

I’m trying to store the database table name as a const so I don’t have to write the below code every time:


$table_name = $wpdb -> prefix . 'name_here';

Instead, I’d like to do it like this:


define ( 'TABLE_NAME', 'wp_name_here' );

But when I use it to create the table, it won’t work…Why?


if ( $wpdb -> get_var ( $wpdb -> prepare ( "SHOW TABLES LIKE TABLE_NAME" ) ) !== TABLE_NAME ) {
   $sql = "CREATE TABLE TABLE_NAME (
      id mediumint(9) NOT NULL AUTO_INCREMENT,
      name tinytext NOT NULL,
      value text NOT NULL,
      PRIMARY KEY (id)
   ) $charset_collate;";
}

The table name now becomes TABLE_NAME if I use the above code.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer