首页 视频课程 WordPress开发文档数据库与媒体库 创建数据表

创建数据表

2023-06-11 / 5807阅

首先,我们需要创建一个名为“wp_posts”的数据表,该表将存储WordPress文章的所有信息。

CREATE TABLE wp_posts (
ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
post_author BIGINT(20) UNSIGNED 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_excerpt TEXT NOT NULL,
post_status VARCHAR(20) NOT NULL DEFAULT 'publish',
comment_status VARCHAR(20) NOT NULL DEFAULT 'open',
ping_status VARCHAR(20) NOT NULL DEFAULT 'open',
post_password VARCHAR(255) 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 LONGTEXT NOT NULL,
post_parent BIGINT(20) UNSIGNED 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(191)),
KEY type_status_date (post_type,post_status,post_date,ID),
KEY post_status_date (post_status,post_date,ID),
KEY post_date (post_date,ID),
KEY post_parent (post_parent),
KEY post_author (post_author)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

接下来,我们可以在这个表中插入一些数据作为示例文章。下面是一个插入示例:

INSERT INTO wp_posts (post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_content_filtered, post_parent, guid, menu_order, post_type, post_mime_type, comment_count) VALUES
(1, '2021-09-01 09:00:00', '2021-09-01 09:00:00', '

这是一篇示例文章。

', '示例文章标题', '示例文章摘要', 'publish', 'open', 'open', '', 'example-post', '', '', '2021-09-01 09:00:00', '2021-09-01 09:00:00', '', 0, '', 0, 'post', '', 0);

这样我们就创建了一个含有一篇示例文章的数据表,并插入了示例数据,可以在WordPress网站上进行查看和管理。

 

阅读文章或者观看视频过程中有任何问题,请下方留言或者联系我Q248758228

大家谈论
    我的见解
    目录