Friday 19 July 2013

Managing Your MySQL Database



✦ wp_terms: This stores the categories you’ve created for posts and links
as well as tags that have been created for your posts.

 


✦ wp_term_relationships: This stores the relationships among the

posts as well as the categories and tags that have been assigned to
them.

✦ wp_term_taxonomies: WordPress has three types of taxonomies by
default: category, link, and tag. This table stores the taxonomy associ-
ated for the terms stored in the wp_terms table.

✦ wp_usermeta: This table features metadata from every user with an
account on your WordPress Web site. This metadata includes

•  A unique user ID

•  A user meta key, meta value, and meta ID, which are unique identi-
fiers for users on your site

Managing Your MySQL Database

✦ wp_postmeta: This includes all posts or pages published to your site
and contains metadata that includes

•  The unique post ID number. (Each blog post has a unique ID number
to set it apart from the others.)

•  The post meta key, meta value (unique numerical identifiers for each
post created on your site), and any custom fields you’ve created for

the post.

✦ wp_posts: This table features the body of any post or page you’ve pub-
lished to your blog, including autosaved revisions and post option set-

tings, such as

•  The post author, date, and time

•  The post title, content, and excerpt

•  The post status (published, draft, or private)

•  The post comment status (open or closed)

•  The post type (page, post, or custom post type)

•  The post comment count

Managing Your MySQL Database

✦ wp_links: This stores the name, URL, and description of all Links
you create by using the WordPress Link Manager. It also stores all the

advanced options for the links you created, if any.

✦ wp_options: This stores all the option settings that you set for
WordPress after you install it, including all theme and plugin option

settings.

Managing Your MySQL Database



•  A unique comment ID number

•  A comment meta key, meta value, and meta ID (unique numerical

identifiers assigned to each comment left by you, or visitors, on your
site)

✦ wp_comments: This table stores the body of the comments published to
your site, including

•  A post ID that specifies which post the comment belongs to

•  The comment content

•  The comment author’s name, URL, IP address, and e-mail address


 

•  The comment date (day, month, year, and time)

•  The comment status (approved, unapproved, or spam)

Managing Your MySQL Database

Currently, WordPress requires MySQL version 4.1.2 (or greater) in order to work correctly. If your Web hosting provider doesn’t have 4.1.2 (or greater) installed on your Web server, kindly ask to upgrade.

After WordPress is installed on your server (which I discuss in Chapter 4 of this minibook), the database gets populated with 11 tables that exist to store different types of data from your WordPress blog. Figure 3-2 displays the structure of the tables, as follows:

✦ wp_commentmeta: This table stores every comment published to your
site contains information, or metadata, that includes

Managing Your MySQL Database

 

Many new WordPress users are intimidated by the MySQL database, per-

haps because it seems to be way above their technical skills or abilities.

Truth be told, regular users of WordPress — those who just use it to publish
content — don’t really ever have to dig into the database unless they want
to. You only need to explore the database if you’re dealing with theme or
plugin development, or with contributing code to the WordPress project. In
this section, we give you a basic overview of the WordPress database stored
in MySQL so that you have an understanding of the structure and know
where items are stored.

Trying Out a Little PHP



A single line of text displays: Testing my new PHP function, as shown in Figure 3-1.

If the testing.php file displays correctly in your browser, congratulations! You programmed PHP to work in a Web browser!

 

If the testing.php file doesn’t display correctly in your browser, a PHP

error message will give you an indication of the errors in your code. (Usually
included with the error message is the line number where the error exists in
the file.)

Trying Out a Little PHP

After you write your code, follow these steps to save and upload your file:

 

1. Save the file to your local computer as testing.php.

2. Upload the testing.php file.

Via File Transfer Protocol, upload testing.php to the root directory of
your Web server. If you need a review on how to use FTP to transfer files
to your web server, review the information presented in Book II, Chapter 2.

3. Open a Web browser and type the address (http://yourdomain.com/

testing.php) in the Web browser’s address bar (where yourdomain is your actual domain name).

Trying Out a Little PHP

9. Type </body> to close the <body> HTML tag from Step 5 and then
press Enter.

This tells the Web browser that you’re done with the body of the Web
page.

10. Type </html> to close the <html> tag from Step 1 and then press Enter.

This tells the Web browser that you’re at the end of the HTML
document.

When you’re done with Steps 1-10, double-check that the code in your text editor looks like this:

Book II

<html>

<head>

<title>This is a Simple PHP Page</title>
</head>

<body>

<?php echo ‘<p>Testing my new PHP function</p>’; ?>
</body>

</html>

Trying Out a Little PHP

6. Type <?php to tell the Web browser to start a PHP function and then
press Enter.

See the preceding section on starting and stopping PHP functions.

7. Type echo ‘<p>Testing my new PHP function</p>’; and then press Enter.

This is the function that you want PHP to execute on your Web page.

This particular function echoes the text “Testing my new PHP function” and displays it on your Web site.

8. Type ?> to tell the Web browser to end the PHP function and then
press Enter.

Trying Out a Little PHP

 

 

3. Type <title>This is a Simple PHP Page</title> and then press Enter.

The <title> HTML tag tells the browser to display the text between two tags as the title of the document in the browser title bar. (Note: All HTML tags need to be opened and then closed, just like PHP tags that we describe in the preceding section. In this case the <title> tag opens the command, and the </title> tag closes it and tells the Web browser that you’re finished dealing with the title).

4. Type </head> to close the <head> tag from Step 2 and then press
Enter.

5. Type <body> to define the body of the Web page and then press Enter.

Anything that appears after this tag displays in the Web browser
window.

Trying Out a Little PHP

 

To test some PHP code, follow these steps to create a simple HTML Web page with an embedded PHP function:

 

1. Open a new, blank file in your default text editor — Notepad

(Windows) or TextMate (Mac) — type <html>, and then press Enter.

The <html> tag tells the Web browser that this is an HTML document and should be read as a Web page.

2. Type <head> and then press Enter.

The <head> HTML tag contains elements that tell the Web browser

about the document; this information is read by the browser but hidden from the Web page visitor.

Exploring PHP Basics

In this case, get_info() represents the tag function, which grabs informa-
tion from the database to deliver it to your blog. The information retrieved
depends on what tag function appears between the two PHP commands.

Every PHP command you start requires a stop command. For every <?php,
you must include the closing ?> command somewhere later in the code.
PHP commands structured improperly cause ugly errors on your site, and
they’ve been known to send programmers, developers, and hosting provid-
ers into loud screaming fits. You find a lot of starting and stopping of PHP
throughout the WordPress templates and functions. The process seems as
though it would be resource intensive, if not exhaustive, but it really isn’t.

Always, always make sure that the PHP start and stop commands are sepa-
rated from the function with a single space. You must have a space after

<?php and a space before ?> — if not, the PHP function code doesn’t work. So make sure that the code looks like this: <?php get_info(); ?> — not like this: <?phpget_info();?>

Exploring PHP Basics



As we state earlier, WordPress is based in PHP (a scripting language for

creating Web pages) and uses PHP commands to pull information from the


 

MySQL database. Every tag begins with the function to start PHP and ends
with a function to stop it. In the middle of those two commands lives the

request to the database that tells WordPress to grab the data and display it.

 

A typical template tag, or function, looks like this:

 

<?php get_info(); ?>

This example tells WordPress to do three things:
✦ Start PHP: <?php

✦ Use PHP to get information from the MySQL database and deliver it to
your blog: get_info();

✦ Stop PHP: ?>

Exploring PHP Basics



Before you play around with template tags (covered in Book VI) in your


WordPress templates or plugin functions, you need to understand what
makes up a template tag and why, as well as the correct syntax, or func-
tion, for a template tag as it relates to PHP. Additionally, have a look at the
WordPress files contained within the download files. Many of the files end
with the .php file extension — an extension required for PHP files, which
separates them from other file types, such as JavaScript (.js) or CSS

(.css).