Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress WP Ulike插件,无法添加其他用户表(PHP)_Php_Mysql - Fatal编程技术网

Wordpress WP Ulike插件,无法添加其他用户表(PHP)

Wordpress WP Ulike插件,无法添加其他用户表(PHP),php,mysql,Php,Mysql,我正在使用Wordpress制作一个网站,人们可以在这里喜欢并对文章发表评论。我正在使用一个名为WP ULike的插件,我想在我的网站中启动该插件时,向该插件创建的数据库中添加另一个表 用于创建所有表的PHP代码如下所示: /** * Fired for each blog when the plugin is activated. * * @since 3.1 */ private static function single_activate() { global $

我正在使用Wordpress制作一个网站,人们可以在这里喜欢并对文章发表评论。我正在使用一个名为WP ULike的插件,我想在我的网站中启动该插件时,向该插件创建的数据库中添加另一个表

用于创建所有表的PHP代码如下所示:

/**
 * Fired for each blog when the plugin is activated.
 *
 * @since    3.1
 */
private static function single_activate() {

    global $wpdb;

    if ( get_site_option( 'wp_ulike_dbVersion' ) != WP_ULIKE_DB_VERSION ) {

        $posts_table = $wpdb->prefix . "ulike";
        if ( $wpdb->get_var( "show tables like '$posts_table'" ) != $posts_table ) {
            $sql = "CREATE TABLE " . $posts_table . " (
                    `id` bigint(20) NOT NULL AUTO_INCREMENT,
                    `post_id` bigint(20) NOT NULL,
                    `date_time` datetime NOT NULL,
                    `ip` varchar(30) NOT NULL,
                    `user_id` varchar(30) NOT NULL,
                    `status` varchar(15) NOT NULL,
                    PRIMARY KEY (`id`)
                );";

            require_once ABSPATH . 'wp-admin/includes/upgrade.php';
            dbDelta( $sql );
        } else {
            // Fix an old issue with user_id column
            $wpdb->query( "ALTER TABLE $posts_table CHANGE `user_id` `user_id` VARCHAR(30) NOT NULL" );
        }
    }
}
$comptencies_table = $wpdb->prefix . "ulike_competencies";
if ( $wpdb->get_var( "show tables like '$competencies_table'" ) != $competencies_table ) {
    $sql = "CREATE TABLE " . $comptencies_table . " (
    `id` bigint(20) NOT NULL AUTO_INCREMENT,
    `competency_id` bigint(20) NOT NULL,
    `date_time_acquired` datetime NOT NULL,
    `ip` varchar(30) NOT NULL,
    `user_id` varchar(30) NOT NULL,
    `competency_value` smallint(5) NOT NULL,
    PRIMARY KEY (`id`)
    );";

    require_once ABSPATH . 'wp-admin/includes/upgrade.php';
    dbDelta( $sql );
} else {
    // Fix an old issue with user_id column
    $wpdb->query( "ALTER TABLE $competencies_table CHANGE `user_id` `user_id` VARCHAR(30) NOT NULL" );
}
当我激活插件时,我可以看到所有的表都很好。所以我决定向数据库中添加另一个表,称为能力表。我的代码如下:

/**
 * Fired for each blog when the plugin is activated.
 *
 * @since    3.1
 */
private static function single_activate() {

    global $wpdb;

    if ( get_site_option( 'wp_ulike_dbVersion' ) != WP_ULIKE_DB_VERSION ) {

        $posts_table = $wpdb->prefix . "ulike";
        if ( $wpdb->get_var( "show tables like '$posts_table'" ) != $posts_table ) {
            $sql = "CREATE TABLE " . $posts_table . " (
                    `id` bigint(20) NOT NULL AUTO_INCREMENT,
                    `post_id` bigint(20) NOT NULL,
                    `date_time` datetime NOT NULL,
                    `ip` varchar(30) NOT NULL,
                    `user_id` varchar(30) NOT NULL,
                    `status` varchar(15) NOT NULL,
                    PRIMARY KEY (`id`)
                );";

            require_once ABSPATH . 'wp-admin/includes/upgrade.php';
            dbDelta( $sql );
        } else {
            // Fix an old issue with user_id column
            $wpdb->query( "ALTER TABLE $posts_table CHANGE `user_id` `user_id` VARCHAR(30) NOT NULL" );
        }
    }
}
$comptencies_table = $wpdb->prefix . "ulike_competencies";
if ( $wpdb->get_var( "show tables like '$competencies_table'" ) != $competencies_table ) {
    $sql = "CREATE TABLE " . $comptencies_table . " (
    `id` bigint(20) NOT NULL AUTO_INCREMENT,
    `competency_id` bigint(20) NOT NULL,
    `date_time_acquired` datetime NOT NULL,
    `ip` varchar(30) NOT NULL,
    `user_id` varchar(30) NOT NULL,
    `competency_value` smallint(5) NOT NULL,
    PRIMARY KEY (`id`)
    );";

    require_once ABSPATH . 'wp-admin/includes/upgrade.php';
    dbDelta( $sql );
} else {
    // Fix an old issue with user_id column
    $wpdb->query( "ALTER TABLE $competencies_table CHANGE `user_id` `user_id` VARCHAR(30) NOT NULL" );
}
上一个表的代码基本相同,但有一些不同的变量,它位于另一个表的代码下面的同一个文件中

但是当我停用并重新激活插件,然后去检查数据库时,新表就不见了

有人知道为什么会这样吗


谢谢

只需更改主文件上的“WP\u ULIKE\u DB\u VERSION”值即可。您还可以在数据库中手动添加此表

您的代码放在哪里?它实际上就在第一个表的代码下面,在专用静态函数single_activate中。我没有插件,但您确定要这样做吗?当插件所有者更新插件时,它可能会覆盖您的代码。问题可能与打字错误有关,因为$Comptenicies_表与$competencies_表不同。嘿,我修复了打字错误,问题仍然存在。插件已经有一段时间没有更新了,所以我有点指望它。由于某种原因,它无论如何都不起作用……当你说它不起作用时,你是指一般的插件还是仅仅是你的代码?