WordPress source code parsing-database table structure (2)

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

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

The 11 data tables in the WordPress database are:

Table Name (click a table name to view details)

Description
Wp_commentmeta Additional information table of article comment
Wp_comments Article comment information table
Wp_links Link info table
Wp_options The basic configuration information table is usually operated by get_option. This table is usually used as a place where the plug-in stores data.
Wp_postmeta Additional data tables of the article, such as the number of browsing times and custom fields of the article, are stored here.
Wp_posts The document information table contains logs, attachments, pages, and other information. Is the most important data table in WordPress.
Wp_terms Document category, link category, and tag information table.
Wp_term_relationships Classification and association tables of the document information table (wp_posts) and Link Table (wp_links.
Wp_term_taxonomy The classification information table identifies the classification types of wp_terms information, including category, link_category, and tag.
Wp_usermeta User extra info table
Wp_users User basic information table. Stores basic information about all users in the system.

WordPressWhat is the relationship between database tables?

To understand this problem and have a deeper understanding of the relationship between WordPress data tables, let's first think about the functions of the Wordpress blog system, by default, wordpress2.6.2 includes user information, category information, link information, article information, article comment information, and basic configuration information.

User information: account information of all registered users in the system.

CATEGORY information: includes the classification information of the document category, link category, and tag.

Link information: Friendship link information in the blog system.

Article information: logs in the blog system, attachments generated by logs, pages, and other information.

Article comment: Comment on a specific log or attachment.

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

The 11 data tables in the WordPress database are designed to store the above 6 types of data information. The overall relationship structure between these tables is shown in:

We can see that the data tables and relationships involved in the six types of data in the Wordpress blog system are as follows:

Information type Involving data tables and associations
User Information Data Table: wp_users, wp_usermeta, Association: wp_users.id-> wp_usermeta.user_id
CATEGORY Information Data Table: wp_terms, wp_term_taxonomy Association: wp_terms.term_id-> wp_term_taxonomy.term_id
Link information

Data Tables: wp_links, wp_term_relationships, wp_terms, wp_term_taxonomy, wp_users, and wp_usermeta associations:

1. Determine the link category (1) wp_links.link_id-> wp_term_relationships.object_id, (2) wp_term_relationships.term_taxonomy_id-> wp_term_taxonomy.term_taxonomy_id
(This relationship also depends on the taxonomy classification Type in the wp_term_taxonomy table as "link_category") (3) wp_terms.term_id-> wp_term_taxonom.term_id

2. Determine the link owner (4) wp_links.link_owner-> wp_users.id (5) wp_users.id-> wp_usermeta.user_id

Article Information

Data Table: wp_posts, wp_postmeta, wp_comments, wp_term_relationships, wp_terms, links, wp_users, wp_usermeta Association: 1. Determine article information (1) wp_posts.id-> wp_postsmeta.post_id

2. Confirm the article comment (2) wp_posts.id-> wp_comments.comment_post_id

3. Determine the author of the article comment (3) wp_comments.comment_author-> wp_users.id

(4) wp_users.id-> wp_usermeta.user_id

Iv. Determine the document 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 in the wp_term_taxonomy table as "Category" or "tag ")

(7) wp_terms-> term_id-> wp_term_taxonomy

5. Determine the author of the article

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

(9) wp_users.id-> wp_usermeta.user_id

Article comment Data Table: wp_comments, wp_posts, wp_users, wp_usermeta Association:
1. Confirm the comment Article (1) wp_comments.comment_post_id-> wp_posts.id
2. Determine the author of the comment (2) wp_comments.comment_author-> wp_users.id (3) wp_users.id-> wp_usermeta.user_id
Basic configuration information Data Table: wp_options is not associated

 

Database settings in the Wp-config.php.

<? PHP/* wp-config.php * // ** MySQL settings-specific information from the host you are using ** // ** WordPress database name */define ('db _ name ', sae_mysql_db);/** MySQL database username */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 sorting type. If you are not sure, do not change */define ('db _ collate ', ''); define ('wp _ use_multiple_db', true ); $ db_list = array ('write' => array (Array ('db _ host' => sae_mysql_host_m. ':'. sae_mysql_port, 'db _ user' => sae_mysql_user, 'db _ password' => sae_mysql_pass, 'db _ name' => sae_mysql_db, 'db _ charset' => 'utf8'), 'read' => array (Array ('db _ host' => sae_mysql_host_s. ':'. sae_mysql_port, 'db _ user' => sae_mysql_user, 'db _ password' => sae_m Ysql_pass, 'db _ name' => sae_mysql_db, 'db _ charset' => 'utf8'),); $ global_db_list = $ db_list ['write']; /** # @ + * set the ID key. ** You can write some characters at will * or directly access the {@ link https://api.wordpress.org/secret-key/1.1/salt/ wordpress.org Private Key Generation Service}. * any modification will invalidate the cookie and all users must log on 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 ', ha Sh_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 need to install multiple WordPress in the same database, set different data table prefixes for each WordPress. * The prefix name can only contain numbers and letters with underscores. */$ Table_prefix = 'wp _ ';/*** set the WordPress language. The default value is English. ** This setting allows Wordpress to display the required language. * A. Mo language file with the same name should be placed in WP-content/ages. * To use the WordPress Simplified Chinese interface, enter zh_cn. */Define ('plang ', 'zh _ cn');/*** for developers: WordPress debugging mode. ** Change this value to "true", and Wordpress will display prompts during all development processes. * It is strongly recommended that plug-in developers enable this function in the development environment. */Define ('wp _ debug', false);/* OK! Do not edit any more. Save the file. * // ** Absolute path of the WordPress directory. */If (! Defined ('abspath') define ('abspath', dirname (_ file _). '/');/** set WordPress variables and include files. This file contains a lot of content and is difficult to analyze */require_once (abspath. 'wp-settings. php ');

The wp-db.php contains a wpdb class that is a database operation API. Generates a global variable of $ wpdb, which is an object of the wpdb class. The post is too bloated.

Refer:

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

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.