[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

WordPress: Adding Table on Plugin Activation / dbDelta

Posted on 2013-01-29
6
Medium Priority
?
588 Views
Last Modified: 2013-02-04
I really could use some help. I'm starting to lose my mind.

I wrote a plugin a ways back, which worked in the past. On install / activation it is supposed to create a table in the database. I've installed the plugin on a new site and I cannot for the life of me get it to create a table like it had before.

I replaced my code with the sample code from the Codex and it works. I just can't see how mine differs.

I've tried to replace what's in the sample code with my own fields and data types and I'm back to square one. The plugin won't write the table.

I know plenty of people have had issues because of dbDelta and how particular it is about formatting. I've tried to follow people's advice for making mine conform to those rules, but to no avail.

Please help me see where I'm going wrong.

global $abc_reviews_db_version;
$abc_reviews_db_version = "1.0";

function abc_reviews_install() {
   global $wpdb;
   global $abc_reviews_db_version;

   $table_name = $wpdb->prefix . "abc_reviews";

$sql = "CREATE TABLE " . $table_name . " (
          id mediumint(9) NOT NULL AUTO_INCREMENT,
          review_date DATE(50) NOT NULL,
          review_author VARCHAR(250) NOT NULL,
          text text NOT NULL,
          UNIQUE KEY id (id)
        );";

require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);

  add_option("abc_reviews_db_version", $abc_reviews_db_version);
}

register_activation_hook(__FILE__,'abc_reviews_install');

Open in new window

0
Comment
Question by:michaelsmith1994
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 1500 total points
ID: 38833829
The plugin won't write the table.

Have you tried turning debug mode on and then installing and running the plugin?
0
 

Author Comment

by:michaelsmith1994
ID: 38833885
I didn't know such an option existed.  Thanks for letting me know.

This is what I got back:

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(50) NOT NULL, review_author VARCHAR(250) NOT NULL, text tex' at line 3]
CREATE TABLE wp_pcg_reviews ( id mediumint(9) NOT NULL AUTO_INCREMENT, review_date DATE(50) NOT NULL, review_author VARCHAR(250) NOT NULL, text text NOT NULL, UNIQUE KEY id (id) )

Do you see the problem?
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 38834054
'text' is a reserved word in MySQL.  Maybe change that to something else and try it.  It might not be a dbDelta issue and instead just a plain old MySQL issue.

(I totally know your frustration.  I had a similar issue with dbDelta once too).
0
Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

 

Author Comment

by:michaelsmith1994
ID: 38835150
I've been changing the code frequently to try and find a way around this issue.
 
Originally that field name was "review_text" and it didn't work.  But just to be thorough, I changed it back and re-uploaded the plugin.  

Unfortunately, I get the same error:

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(50) NOT NULL, review_author VARCHAR(250) NOT NULL, review_t' at line 3]
CREATE TABLE wp_pcg_reviews ( id mediumint(9) NOT NULL AUTO_INCREMENT, review_date DATE(50) NOT NULL, review_author VARCHAR(250) NOT NULL, review_text text NOT NULL, UNIQUE KEY id (id) )

0
 

Author Comment

by:michaelsmith1994
ID: 38851724
My SQL code was bad news bears.

I think I was misusing date() by passing it a character limit.

My inexperience was at fault.  Thanks for the help.
0
 

Author Closing Comment

by:michaelsmith1994
ID: 38851725
This got me on the right path.  Thanks.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
The viewer will learn how to count occurrences of each item in an array.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question