WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Multiple Database Tables for Plugin (2 posts)

  1. allstar
    Member
    Posted 6 years ago #

    On activation I'm trying to have WP create 2 tables that my 'plugin' will need. I've tried using deltadb() and wpdb->query.

    The SQL is properly formed (literally just a cut and paste out of a MySQL 4.0 export).

    I either get 1 table created or none respectively. Where am I going wrong?


    require_once(ABSPATH . "wp-admin/upgrade-functions.php");
    // if database table doesn't already exist
    if ($installed_ver === false || $installed_ver != $plugin_db_version) {

    $sql_one = "CREATE TABLE " . $this->db_table_one . " (
    <FIELDS>
    ) TYPE=InnoDB;";
    dbDelta($sql_one);

    $sql_two = "CREATE TABLE " . $this->db_table_two . " (
    <FIELDS>
    ) TYPE=InnoDB;";
    dbDelta($sql_two);
    }

  2. allstar
    Member
    Posted 6 years ago #

    The initial test was creating 1 Database table. Which stored the database version number.

    The reason the plugin didn't create the 3 tables was it was checking to see if the current database was a modern version. Which it was so it didn't need to add the 'new' tables.

    Deleting the database version number from wp_options allowed all 3 tables to be created on installation.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.