admin管理员组文章数量:1415420
Can we consider the Wordpress database a relational database? Some tables are related to each other, but it doesn't work with foreign keys. So, is it a relational database??
Can we consider the Wordpress database a relational database? Some tables are related to each other, but it doesn't work with foreign keys. So, is it a relational database??
Share Improve this question asked Aug 31, 2019 at 19:51 Rowayda KhayriRowayda Khayri 1215 bronze badges 2- There is no "WordPress database". WordPress does use MySQL or MariaDB, which are relational databases. – fuxia ♦ Commented Aug 31, 2019 at 21:18
- 1 @fuxia I mean the structure of the database in Wordpress. – Rowayda Khayri Commented Aug 31, 2019 at 21:28
2 Answers
Reset to default 1The data within the database has functionals relationships. For example, user_meta
and user
. In that regard, it would be considered relational data.
On the other hand, if you mean, that referential integrity is strictly enforced, no it is not. This is mostly a product of MyISAM which is faster but does not support foreign key checks. On the whole, with projects such as WordPress, a simple index of fields used in WHERE
clauses more than suffice.
This is often the same as most projects that use MySQL - the table relationships are implied through naming but enforced at the logic layer, not the data layer. This is because only WordPress is expected to read the database and nothing else. Therefore there is no reason to put data and key services into action (which is the design rationale behind MyISAM (as far as I understand).
If you were to dig intot the core of WordPress, you would find WHERE
clauses and even joins which expect there to be a relationship between data in one table and data in another. Comments would not work if the individual comments could not be tracked back to the post they were made on. Which is why comments and posts are considered related.
TL;DR: Yes but the key relationships are not enforced due to design considerations.
As to if WordPress covers the requirements of, say, third normal form, that's a whole other debate.
Foreign key constraints cannot be used with MyISAM tables. InnoDB tables support them. You can change all MyISAM tables to InnoDB tables with the following code:
function changeAllMyIsamToInnoDB() {
global $wpdb;
$sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'your-database-name'
AND ENGINE = 'MyISAM'";
$rs = $wpdb->get_results($sql);
foreach ($rs as $row) {
$tbl = $row->TABLE_NAME;
$sql = "ALTER TABLE `$tbl` ENGINE=INNODB";
$wpdb->query($sql);
}
}
changeAllMyIsamToInnoDB();
Do your database backup, first!
Insert the above code into functions.php of your current theme, replacing your-database-name
with the name of your database.
Remove the code after the change is done.
本文标签: Wordpress Relational Database
版权声明:本文标题:Wordpress Relational Database 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745196234a2647146.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论