$sql = "CREATE TABLE 'my_custom_table'(
id mediumint(9) NOT NULL AUTO_INCREMENT,
time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
name tinytext NOT NULL,
text text NOT NULL,
url VARCHAR(55) DEFAULT '' NOT NULL,
UNIQUE KEY id (id)
);";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
This is my code. It produce an error when I try to execute it. However, if I replace the my_custom_table
string with a variable $table_name = 'my_custom_table';
This works. Why??
The proper notation is:
Single quotes define strings. Backticks escape table names.
It’s possible you did this in your alternate version:
The backticks are not required unless your table name contains a non-standard character (outside A-Z, 0-9 or _), or is a reserved word. It’s safe to use them in all circumstances, though, if you prefer to be consistent.