1

我正在尝试创建一个 Wordpress 插件。稍后将提供用于设置数据库表的代码。但是,我面临的问题与其说是错误不如说是缺乏错误。不管我做什么,dbdelta 似乎什么都不做——而且 wordpress 不会产生任何相关的错误,至少给我一个关于出了什么问题的线索。

代码是:

function create_tables()
{
    global $wpdb;
    $pl_nm = VSystem::$plugin_name;
    $create_voters = "create table if not exists {$wpdb->prefix}{$pl_nm}_voters(
        ID bigint(20) unsigned auto_increment,
        user_id bigint(20) unsigned not null,
        primary key  (ID),
        foreign key (user_id) references {$wpdb->prefix}users(ID)
    );";

    $create_links = "create table if not exists {$wpdb->prefix}{$pl_nm}_links(
        ID bigint(20) unsigned auto_increment,
        product bigint(20) unsigned,
        name varchar(256) not null,
        url varchar(512) not null,
        description text,
        posted datetime,
        poster bigint(20) unsigned not null,
        primary key  (ID),
        foreign key (poster) references {$wpdb->prefix}users(ID)
    );";

    $create_votes = "create table if not exists {$wpdb->prefix}{$pl_nm}_votes(
        ID bigint(20) unsigned auto_increment,
        link_id bigint(20) unsigned not null,
        voter_id bigint(20) unsigned not null,
        choice int not null,
        primary key  (ID),
        foreign key (link_id) references {$wpdb->prefix}{$pl_nm}_links(ID),
        foreign key (voter_id) references {$wpdb->prefix}users(ID)
    );";
    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    dbDelta( $create_voters );
    dbDelta( $create_links );
    dbDelta( $create_votes );
    dbDelta("asdasdsadsad");
    //wp_die("{$wpdb->prefix}{$pl_nm}");



    add_option('db_version', VSystem::$defaults['db_version']);
}

function vsystem_install()
{
    create_tables();
}

现在我知道这个函数至少被调用了,因为取消注释 wp_die 命令的行为是应该的。我能得到任何帮助吗?

    dbDelta("asdasdsadsad");

即便如此,似乎也没有产生任何回应。如果有人能告诉我如何让 dbdelta 做任何事情,我也许可以自己做这件事。

4

0 回答 0