Bill: WordPress Source parsing-database table structure

Source: Internet
Author: User
Tags mysql host sha1 wordpress database wordpress blog wordpress debug

If it is a normal user, do not need to understand the structure of the WordPress database. However, if you are writing a plugin, you should be interested in how WordPress handles its data and relationships. If you have tried to use the existing WordPress API to access the data you need, but do not directly access the database, it is impossible, WordPress provides wpdb class, make this task become simple.

The 11 data tables of the WordPress database are:

Table name (click on the table name to see more information)

Describe
Wp_commentmeta Article Comment Additional Information sheet
Wp_comments Article Comment Information table
Wp_links Link Information table
Wp_options The Basic configuration information table, typically operated by get_option, is typically used as a place for the plug-in to store data.
Wp_postmeta Additional data sheets, such as article views, custom fields for articles, etc. are stored here.
Wp_posts The article Information table, includes the log, the attachment, the page and so on information. Is the most important data table of WordPress.
Wp_terms Article classification, link classification, label information table.
Wp_term_relationships The association table of classification and article Information table (wp_posts), link table (wp_links).
Wp_term_taxonomy Classification information table, distinguish the classification type of wp_terms information, there are category, Link_category and tag three classification types.
Wp_usermeta User additional Information table
Wp_users User basic information table. Store all user basic information of the system.

WordPress What is the relationship between database tables?

To understand this problem and the relationship between the WordPress data table has a deeper understanding, let us first think of WordPress blog system features, the default installation of the WordPress2.6.2 version of the blog system involves the data information mainly includes the user information, classification information, Link information, article information, article comment information, basic configuration information 6 types of information.

User information: Account information for all registered users in the system.

Classification information: Including the article classification, link classification, label 3 of the classification information.

Link information: Is the blog system of Friendship links information.

Article Information: Blog system of logs, logs generated attachments, pages and other information.

Article comment information: Comments on specific logs or attachments.

Basic configuration information: Basic configuration information in the system, such as blog name, blog address, and so on.

The 11 data tables of the WordPress database are designed to store the above 6 types of data information, and the overall relationship structure between these tables is as follows:

It can be seen from the WordPress blog System 6 types of data information related to the data table and the relationship as shown in the following table:

Type of information Related data tables and related relationships
User Information Data sheet: wp_users, Wp_usermeta, relational: Wp_users. id->wp_usermeta.user_id
Classification information Data sheet: wp_terms, wp_term_taxonomy Association: wp_terms.term_id->wp_term_taxonomy.term_id
Link information

Datasheets: Wp_links, Wp_term_relationships, Wp_terms, wp_term_taxonomy, Wp_users, Wp_usermeta associations:

One, determine the link belongs to the category (1) wp_links.link_id->wp_term_relationships.object_id, (2) wp_term_relationships.term_taxonomy_id- >wp_term_taxonomy.term_taxonomy_id
(The relationship also depends on the taxonomy classification type "Link_category" in the Wp_term_taxonomy Table) (3) wp_terms.term_id->wp_term_taxonom.term_id

Second, determine the link owner (4) wp_links.link_owner->wp_users. ID (5) wp_users. id->wp_usermeta.user_id

article Information

Data sheet: wp_posts, Wp_postmeta, Wp_comments, Wp_term_relationships, Wp_terms, Wp_term_taxonomy, Wp_users, Wp_usermeta related relations: First, determine the article information (1) wp_posts. id->wp_postsmeta.post_id

Two, determine the article Comments (2) wp_posts. id->wp_comments.comment_post_id

Third, determine the author of the article Comments (3) wp_comments.comment_author->wp_users.id

(4) Wp_ Users. id->wp_usermeta.user_id

Four, determine the article belongs to the category

(5) wp_posts. id->wp_term_relationships.object_id,

(6) Wp_term_relationships.term_taxonomy_id->wp_term_ taxonomy.term_taxonomy_id
(This relationship also depends on the taxonomy classification type "category" or "tag" in the Wp_term_taxonomy table)

(7) wp_terms- >term_id->wp_term_taxonomy

Five, determine the author of the article

(8) wp_posts.author->wp_users.id;

(9) wp_users. id->wp_usermeta.user_id

Article Comment Information Data sheet: wp_comments, wp_posts, wp_users, Wp_usermeta Association relationships:
I. Determination of comments articles (1) wp_comments.comment_post_id->wp_posts.id
Ii. the author (2) determining the comment wp_comments.comment_author->wp_users. ID (3) wp_users. id->wp_usermeta.user_id
Basic configuration information Data table: Wp_options no correlation relationship

The settings for the database in wp-config.php.

<?PHP/*wp-config.php*/        //* * MySQL Settings-specific information from the host you are using * *///** Name of WordPress database*/    Define(' Db_name ',sae_mysql_db); /** MySQL Database user name*/    Define(' Db_user ',sae_mysql_user); /** MySQL Database Password*/    Define(' Db_password ',Sae_mysql_pass); /** MySQL Host*/    Define(' Db_host ', sae_mysql_host_m. ': '.sae_mysql_port); /** Default text encoding when creating a data table*/    Define(' Db_charset ', ' UTF8 '); /** Database grooming type. If you are unsure do not change*/    Define(' Db_collate ', '); Define(' wp_use_multiple_db ',true); $db _list=Array(            ' Write ' = =Array(                Array(                    ' Db_host ' and sae_mysql_host_m. ': '.                    Sae_mysql_port, ' db_user ' = sae_mysql_user, ' Db_password ' and Sae_mysql_pass, ' Db_name ' = sae_mysql_db, ' db_charset ' and ' UTF8 '                    )                ), ' read ' =Array(                Array(                    ' Db_host ' and sae_mysql_host_s. ': '.                    Sae_mysql_port, ' db_user ' = sae_mysql_user, ' Db_password ' and Sae_mysql_pass, ' Db_name ' = sae_mysql_db, ' db_charset ' and ' UTF8 '                    )                ),            ); $global _db_list=$db _list[' Write ']; /**#@+ * Identity key setting. * * You can write some characters * or directly access {@link https://api.wordpress.org/secret-key/1.1/salt/WordPress.org private key Generation service}, * Any changes will result in Cook   IE fails, all users must log in again. * * @since 2.6.0*/    Define(' Auth_key ', Hash_hmac (' SHA1 ', Sae_accesskey. ' Auth_key ',Sae_secretkey)); Define(' Secure_auth_key ', Hash_hmac (' SHA1 ', Sae_accesskey. ' Secure_auth_key ',Sae_secretkey)); Define(' Logged_in_key ', Hash_hmac (' SHA1 ', Sae_accesskey. ' Logged_in_key ',Sae_secretkey)); Define(' Nonce_key ', Hash_hmac (' SHA1 ', Sae_accesskey. ' Nonce_key ',Sae_secretkey)); Define(' Auth_salt ', Hash_hmac (' SHA1 ', Sae_accesskey. ' Auth_salt ',Sae_secretkey)); Define(' Secure_auth_salt ', Hash_hmac (' SHA1 ', Sae_accesskey. ' Secure_auth_salt ',Sae_secretkey)); Define(' Logged_in_salt ', Hash_hmac (' SHA1 ', Sae_accesskey. ' Logged_in_salt ',Sae_secretkey)); Define(' Nonce_salt ', Hash_hmac (' SHA1 ', Sae_accesskey. ' Nonce_salt ',Sae_secretkey)); /**#@-*/        /** * WordPress data table prefix.   * * If you have the need to install multiple wordpress in the same database, please set a different data table prefix for each wordpress.   * Prefix names can only be underlined for numeric characters and letters. */    $table _prefix= ' Wp_ '; /** * WordPress language settings, default to English.   * * This setting allows WordPress to display the language you need.   * wp-content/languages. Mo language files should be placed in the same name.   * To use the WordPress Simplified Chinese interface, just fill in the ZH_CN. */    Define(' Wplang ', ' ZH_CN '); /** * Developer-specific: WordPress debug mode.   * * To change this value to "true", WordPress will display all the prompts during the development process.   * Plugin developers are strongly encouraged to enable this feature in the development environment. */    Define(' Wp_debug ',false); /*It's all right! Please do not continue editing. Please save the file. */        /** The absolute path of the WordPress directory. */    if( !defined(' Abspath ') )        Define(' Abspath ',dirname(__file__) . ‘/‘); /** Set WordPress variables and include files. This file is a lot of content ah, analysis more difficult*/    require_once(Abspath. ' wp-settings.php ');

The wp-db.php contains a wpdb class, which is the database Operations API. Produces a $wpdb global variable, which is an object of the Wpdb class. Very long, posted in the article is too bloated.

Reference:

Http://wenku.baidu.com/view/6448da5bbe23482fb4da4c94.html?from_page=view&from_mod=download

Http://codex.wordpress.org/Database_Description

Http://codex.wordpress.org/Function_Reference/wpdb_Class

http://www.jakc.net/post/272

Original: http://blog.csdn.net/liujiyong7/article/details/8042132

Bill: WordPress Source parsing-database table structure (GO)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.