为什么此查询引发错误?

时间:2018-08-07 02:19:59

标签: mysql mariadb

我正在将一个古老的站点迁移到一个较新的服务器上,该站点的Wordpress版本太旧,无法升级。我不是创建该网站的人,并且我正在尝试进行必要的最小更改以使其正常运行。现在,它抛出一个MySQL错误。这是有问题的查询:

click: function (e) {
    var curobj = this;
    $.ajax({
        url: "/path/to/test.html",
        dataType: "html",
        success: function(data){
            hs.htmlExpand(null, {
                pageOrigin: {
                    x: e.pageX || e.clientX,
                    y: e.pageY || e.clientY
                },
                headingText: curobj.series.name,
                maincontentText: data,
                width: 300
            });
        }

    });
}

将此查询粘贴到PHPMyAdmin中会引发以下错误:

SELECT `wp_posts`.`post_title` as title, `wp_posts`.`post_date` as date, `wp_posts`.`post_name` as slug
    FROM `wp_posts`, `wp_categories`
    JOIN `wp_post2cat` ON `wp_posts`.`ID` = `wp_post2cat`.`post_id`
    WHERE wp_categories.cat_name = 'Stories'
    AND `wp_post2cat`.`category_id` = `wp_categories`.`cat_ID`
    ORDER BY date DESC
    LIMIT 0,10;

这显然不是正确的错误,因为wp_posts.ID实际上确实存在,并且查询在旧主机(可能正在运行旧版本的MySQL)上工作。

那么,由于错误消息是错误的,真正的问题是什么?

MySQL版本:#1054 - Unknown column 'wp_posts.ID' in 'on clause'

编辑

为回应评论,这是有问题的表的结构:

10.2.13-MariaDB-10.2.13+maria~xenial - mariadb.org

CREATE TABLE `wp_posts` (
 `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
 `post_author` bigint(20) NOT NULL DEFAULT 0,
 `post_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
 `post_date_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
 `post_content` longtext NOT NULL,
 `post_title` text NOT NULL,
 `post_category` int(4) NOT NULL DEFAULT 0,
 `post_excerpt` text NOT NULL,
 `post_status` enum('publish','draft','private','static','object','attachment','inherit','future') NOT NULL DEFAULT 'publish',
 `comment_status` enum('open','closed','registered_only') NOT NULL DEFAULT 'open',
 `ping_status` enum('open','closed') NOT NULL DEFAULT 'open',
 `post_password` varchar(20) NOT NULL DEFAULT '',
 `post_name` varchar(200) NOT NULL DEFAULT '',
 `to_ping` text NOT NULL,
 `pinged` text NOT NULL,
 `post_modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
 `post_modified_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
 `post_content_filtered` text NOT NULL,
 `post_parent` bigint(20) NOT NULL DEFAULT 0,
 `guid` varchar(255) NOT NULL DEFAULT '',
 `menu_order` int(11) NOT NULL DEFAULT 0,
 `post_type` varchar(20) NOT NULL DEFAULT 'post',
 `post_mime_type` varchar(100) NOT NULL DEFAULT '',
 `comment_count` bigint(20) NOT NULL DEFAULT 0,
 PRIMARY KEY (`ID`),
 KEY `post_name` (`post_name`),
 KEY `type_status_date` (`post_type`,`post_status`,`post_date`,`ID`)
) ENGINE=MyISAM AUTO_INCREMENT=54 DEFAULT CHARSET=utf8

CREATE TABLE `wp_categories` (
 `cat_ID` bigint(20) NOT NULL AUTO_INCREMENT,
 `cat_name` varchar(55) NOT NULL DEFAULT '',
 `category_nicename` varchar(200) NOT NULL DEFAULT '',
 `category_description` longtext NOT NULL,
 `category_parent` bigint(20) NOT NULL DEFAULT 0,
 `category_count` bigint(20) NOT NULL DEFAULT 0,
 `link_count` bigint(20) NOT NULL DEFAULT 0,
 `posts_private` tinyint(1) NOT NULL DEFAULT 0,
 `links_private` tinyint(1) NOT NULL DEFAULT 0,
 PRIMARY KEY (`cat_ID`),
 KEY `category_nicename` (`category_nicename`)
) ENGINE=MyISAM AUTO_INCREMENT=18 DEFAULT CHARSET=utf8

1 个答案:

答案 0 :(得分:1)

尝试删除wp_categories中的FROM,然后将JOIN用作表。