Title: Storing database table name as const
Last modified: November 12, 2022

---

# Storing database table name as const

 *  Resolved [ace0930](https://wordpress.org/support/users/ace0930/)
 * (@ace0930)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/storing-database-table-name-as-const/)
 * 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.

Viewing 1 replies (of 1 total)

 *  Thread Starter [ace0930](https://wordpress.org/support/users/ace0930/)
 * (@ace0930)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/storing-database-table-name-as-const/#post-16191105)
 * Ok, I didn’t release the double quotes. Only Variable are parsed within it but
   not Constant.

Viewing 1 replies (of 1 total)

The topic ‘Storing database table name as const’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 1 participant
 * Last reply from: [ace0930](https://wordpress.org/support/users/ace0930/)
 * Last activity: [3 years, 8 months ago](https://wordpress.org/support/topic/storing-database-table-name-as-const/#post-16191105)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
