I need to define a table name when creating in MySQL, the first part is a defined prefix and last part is my own table name, I’d like to avoid creating an additional variable to hold them both before passing them to my query.
My code is wrapped in a class, I have defined my table name a private static variable, my code looks valid but doesn’t work.
This is what I’ve tried so far:
CREATE TABLE '$wpdb->prefix.self::$table' // doesn't work
CREATE TABLE self::$table // doesn't work
CREATE TABLE $wpdb->prefix // works
CREATE TABLE {$wpdb->prefix.self::$table} // error
CREATE TABLE $wpdb->prefix.self::$table // just stupid
$tableName = $wpdb->prefix.self::$table;
CREATE TABLE $tableName // works
Can anybody give me a knowledge concussion?
A static property will not be properly interpolated inside a double-quoted string. You need to concatenate it.