Why I cant create table directly using CREATE in wordpress

$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,
  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:

CREATE TABLE `my_custom_table`

Single quotes define strings. Backticks escape table names.

It's possible you did this in your alternate version:

CREATE TABLE my_custom_table

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.

Tags: Mysql / Wordpress

Similar questions

Why cant the WP Filesystem API read googlefonts.json?
I've inherited a site built with a theme by Highgrade (southcentral) which is built using the Redux framework. I'm seeing the following error in the frontend and admin panel: I've tried altering permissions and ownership on googlefonts.json but to no avail. The problem seems to be within the Redux framework - see this thread on github I'm debugging...
Why cant I add a custom post type to a custom taxonomy?
I am trying to assign a custom taxonomy to a custom post type with wp_insert_post function. A quick fix for now is: However, I want to do it with wp_insert_post function. NOTE I am using the following inside the $args for register_post_type( 'custom_post_type', $args ); So, what am I missing?
Why is it I cant set a get variable
I am appending ?readmore=true to the end of a url in wordpress but on the next page I tried this and in my print_r I get this Am I missing something about get variables in wordpress
Why cant i access ajax pulled content with jquery
Possible Duplicate: Use variable outside the success function from an ajax/jquery call I have this code and i don't understand why the accessing of the html elements is only working inside the ajax success function. the form is pulled in from ajax either way but i can only access it when i put all the selects for elements of it inside the ajax func...
Why i cant install plugins and themes in my local host?
All i get is this error page why is that? I am running wamp on windows10. http://prntscr.com/84fikq
I cant drop tables after uninstalling plugin in WP, why?
In uninstall.php I have this part of code, when I delete my plugin after it, I see that in my db I have all my plugin tables:

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.