Support » Fixing WordPress » Problem using wpdb

  • singhal_pooja_j


    I want to create a table using wpdb and dbDelta.
    The code is as follows. But the table is not getting created and I’m also not getting any error message.

    $sql = “create table $table_name (
    club_id int(11) NOT NULL auto_increment,
    project_name varchar(500) NOT NULL,
    first_name varchar(100) NOT NULL,
    school_status varchar(50) NOT NULL,
    school_name varchar(200) NOT NULL,
    school_city varchar(50) NOT NULL,
    school_state varchar(50) NOT NULL,
    year_in_school varchar(50) NOT NULL,
    age int(2) NOT NULL,
    email varchar(200) NOT NULL,
    mobile varchar(15) NOT NULL,
    chat_id varchar(50) NOT NULL,
    facebook_page_link varchar(200) NOT NULL,
    mailing_address_street varchar(50) NOT NULL,
    mailing_address_city varchar(50) NOT NULL,
    mailing_address_state varchar(50) NOT NULL,
    mailing_address_zip char(6) NOT NULL,
    social_networking varchar(50) NOT NULL,
    organization_involvement varchar(2000) NOT NULL,
    club_heard varchar(50) NOT NULL,
    volunteer_experience varchar(2000) NOT NULL,
    volunteer_reason varchar(2000) NOT NULL,
    skills varchar(2000) NOT NULL,
    creative_ideas varchar(5000) NOT NULL,
    other_information varchar(2000) NOT NULL,
    face_photo_url varchar(200),
    school_image_url varchar(200),
    video_clip_url varchar(200),
    PRIMARY KEY (club_id)

    require_once(ABSPATH . ‘wp-admin/includes/upgrade.php’);

    Can you guys please help?
    Thanks a lot in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • s_ha_dum


    dbDelta is really picky.

    • You have to put each field on its own line in your SQL statement.
    • You have to have two spaces between the words PRIMARY KEY and the definition of your primary key.
    • You must use the key word KEY rather than its synonym INDEX and you must include at least one KEY.
    • You must not use any apostrophe around field’s name. (otherwise dbDelta will encounter a bug during preg_match)

    If you have MySQL less that 5.0.3 you may have trouble with those varchar definitions.

    Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later versions….

    I don’t know if that is a factor. Maybe dbDelta doesn’t like it even if the database would accept it.

    Nothing really stands out though…



    Thanks s_ha_dum for the reply.
    I have taken of all the rules to be followed when using dbDelta. Also I’m using MySQL5.0.95.
    I’m able to create the table using phpMyAdmin but not through plugin code.



    I have had mysterious trouble with dbDelta in the past. There are things I never worked out. It is a frustrating function.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Problem using wpdb’ is closed to new replies.