WordPress数据库错误您的SQL语法有错误;请检查与您的MySQL服务器版本对应的手册

时间:2013-10-11 作者:need-help

wordpress更新到3.5以上后,我发现这个插件有错误。

我不知道如何修理它。如果有人能帮我解决这些问题,或者给我一个如何解决的例子

以下是插件的完整代码:http://pastebin.com/pVUXjWat

我得到的错误:

WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'wp_jsrm_menus\' at line 1 for query SHOW TABLES LIKE wp_jsrm_menus made by activate_plugin, do_action(\'activate_simple-retail-menus/simple-retail-menus.php\'), call_user_func_array, jsrm_activate_loop, jsrm_activate
WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'wp_jsrm_items\' at line 1 for query SHOW TABLES LIKE wp_jsrm_items made by activate_plugin, do_action(\'activate_simple-retail-menus/simple-retail-menus.php\'), call_user_func_array, jsrm_activate_loop, jsrm_activate
WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'wp_jsrm_menus\' at line 1 for query SHOW TABLES LIKE wp_jsrm_menus made by do_action(\'activate_simple-retail-menus/simple-retail-menus.php\'), call_user_func_array, jsrm_activate_loop, jsrm_activate
WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'wp_jsrm_items\' at line 1 for query SHOW TABLES LIKE wp_jsrm_items made by do_action(\'activate_simple-retail-menus/simple-retail-menus.php\'), call_user_func_array, jsrm_activate_loop, jsrm_activate
WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'wp_jsrm_menus\' at line 1 for query SHOW TABLES LIKE wp_jsrm_menus made by do_action(\'activate_simple-retail-menus/simple-retail-menus.php\'), call_user_func_array, jsrm_activate_loop, jsrm_activate
WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'wp_jsrm_items\' at line 1 for query SHOW TABLES LIKE wp_jsrm_items made by do_action(\'activate_simple-retail-menus/simple-retail-menus.php\'), call_user_func_array, jsrm_activate_loop, jsrm_activate
WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'wp_jsrm_menus\' at line 1 for query SHOW TABLES LIKE wp_jsrm_menus made by activate_plugin, do_action(\'activate_simple-retail-menus/simple-retail-menus.php\'), call_user_func_array, jsrm_activate_loop, jsrm_activate
WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'wp_jsrm_items\' at line 1 for query SHOW TABLES LIKE wp_jsrm_items made by activate_plugin, do_action(\'activate_simple-retail-menus/simple-retail-menus.php\'), call_user_func_array, jsrm_activate_loop, jsrm_activate
此处的所有sql查询

function jsrm_activate() {
        add_option(\'jsrm_val_cols\', \'2\');

        global $wpdb;
        $jsrm_menu_table = $wpdb->prefix . "jsrm_menus";
        $jsrm_item_table = $wpdb->prefix . "jsrm_items";

        require_once(ABSPATH . \'wp-admin/includes/upgrade.php\');

        if (!empty ($wpdb->charset))
                $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
        if (!empty ($wpdb->collate))
                $charset_collate .= " COLLATE $wpdb->collate";

        if ($wpdb->get_var( "SHOW TABLES LIKE $jsrm_menu_table") != $jsrm_menu_table){

                $sql1 = "CREATE TABLE IF NOT EXISTS $jsrm_menu_table (
                                id mediumint(9) NOT NULL AUTO_INCREMENT,
                                menuorder mediumint(9) NOT NULL,
                                name tinytext NOT NULL,
                                description text,
                                label tinytext NOT NULL,
                                itemheader tinytext NOT NULL,
                                valueheader tinytext NOT NULL,";

                for ($v=2;$v<=JSRM_VALUE_COLS;$v++){
                        $sql1 .= "valueheader" . $v . " tinytext NOT NULL,";
                };             
                $sql1 .= "UNIQUE KEY id (id)
                                ) $charset_collate;";

                dbDelta($sql1);
        }

        if ($wpdb->get_var( "SHOW TABLES LIKE $jsrm_item_table") != $jsrm_item_table){

                        $sql2 = "CREATE TABLE IF NOT EXISTS $jsrm_item_table (
                                id mediumint(9) NOT NULL AUTO_INCREMENT,
                                menu mediumint(9) NOT NULL,
                                itemorder mediumint(9) NOT NULL,
                                item tinytext NOT NULL,
                                description text,
                                image tinytext,
                                linked tinyint(1),
                                linkurl tinytext,
                                itemhidden tinyint(1),
                                value tinytext,";

                        for ($v=2;$v<=JSRM_VALUE_COLS;$v++){
                                $sql2 .= "value" . $v . " tinytext,";
                        };     
                        $sql2 .= "UNIQUE KEY id (id)
                                ) $charset_collate;";
                dbDelta($sql2);
        }

}


// CHECK DATABASE TABLES ON INIT AND UPDATE IF NECESSARY

function jsrm_check_database_version(){
        $dbversion = get_option( \'jsrm_db_version\', \'1\' );
        if ($dbversion != JSRM_DB_VERSION){
                jsrm_activate_loop();
        }
}
add_action(\'init\', \'jsrm_check_database_version\');

1 个回复
SO网友:s1lv3r

有多种方法可以解决此问题。您可以删除包含SHOW TABLES LIKE (删除行:117、135和137、157)。这应该在dbDelta函数检查表是否已经存在时起作用。或者您可以在第117行和第137行的表名中添加一些单引号:

"SHOW TABLES LIKE \'$jsrm_menu_table\'"

结束

相关推荐

使用META_QUERY订购MySQL样式的日期时间戳

我有一个自定义的post类型字段,我将数据存储在名为football\\u game\\u datetime的字段中。此字段的格式和值示例如下:“2013-10-31 14:00:00”、“2013-09-16 20:00:00”、“2013-09-30 22:00:00”。我使用的代码如下所示,但它没有达到我认为应该达到的效果:$mypost = array( \'post_type\' => \'football_games\', \'meta_query