• I am trying to create my first plugin, and after trying to follow a tutorial on creating a sql table on activation (http://codex.ww.wp.xz.cn/Creating_Tables_with_Plugins), it still doesn’t want to create it! Anyone know what is causing this?

    $wplinker_db_version = “1.0”;

    function wplinker_install () {
    global $wpdb;
    global $wplinker_db_version;

    //Create our table (http://codex.ww.wp.xz.cn/Creating_Tables_with_Plugins)

    $table_name = $wpdb->prefix . “wplinker”;

    if($wpdb->get_var(“show tables like ‘$table_name'”) != $table_name) {

    $sql = “CREATE TABLE ” . $table_name . ” (
    name tinytext NOT NULL,
    url VARCHAR(55) NOT NULL
    );”;

    require_once(ABSPATH . ‘wp-admin/upgrade-functions.php’);
    dbDelta($sql);

    //Add initial data to our table

    $linker_name = “Solipsus”;
    $linker_url = “http://www.solipsus.com”;

    $insert = “INSERT INTO ” . $table_name .
    ” (time, name, text) ” .
    “VALUES (‘” . time() . “‘,'” . $wpdb->escape($linker_name) . “‘,'” . $wpdb->escape($linker_url) . “‘)”;

    $results = $wpdb->query( $insert );

    add_option(‘wplinker’, $wplinker);

    }
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter urbenkeach

    (@urbenkeach)

    Anyone got any suggestions?

    Perhaps you need this code :
    register_activation_hook(__FILE__,'wplinker_install');
    I do try the jal_install to and at first time like you do and it won’t create table while i try to activate the plugin.
    And then i check this code and it works.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘New plugin not creating table on activation.’ is closed to new replies.