There is no shortage of books to help you learn PHP and MySQL together. Julie C. Meloni's PHP, MySQL and Apache All in One will get you off to a great start.
Every bit of content in your blog—posts, sidebars, stylesheets, comments, graphics, dashboard, and all the rest—is stored in the MySQL database you set up during your installation (or that WordPress.com set up for you when you launched your hosted blog). What happens when your site has a visitor? In a matter of seconds, all this goes on, as in Figure 11.1:
1. A visitor's web browser calls on a page from your site.
2. The web server sees a PHP script on the requested page and fires up its PHP interpreter (mod_php5 in Apache) to execute the code.
3. Some of those PHP commands allow the script to connect to the MySQL database as the WordPress user and ask the database for the content that belongs on the page.
4. The MySQL database retrieves the requested content and sends it back to the PHP script (more precisely, to the page it's on).
5. The script, in turn, pours all of this content into a few variables.
6. The script then echoes the content from the variables for display on the page.
7. The script combines the database content with any plain HTML included on the requested page and hands it back to the web server.
8. The web server sends the HTML page back to the browser.
9. The visitor (ideally) becomes enlightened, entertained, enthralled, or some combination thereof. She tells you so on the comments page, beginning the process over again.
Send HTML Output
Send HTML Output
How PHP and MySQL work together to make a web page.
Why store your content in a database when it's just text? Isn't it just easier to have this material surrounded with some variant of HTML or XML tags? When you think about a blog as a moving target, a combination of static and dynamic elements, the answer becomes apparent rather quickly. Maintaining a blog full of static posts quickly becomes a logistical nightmare.
Coming up with enough blog content to keep people visiting can be hard enough without having to continually think about how many posts should be on the front page, making individual perma-linked pages for each of your posts, and all the comments people make on them. This is a job ripe for automation, and the best way to automate content delivery is by keeping your data in one easily accessed place.
Was this article helpful?
It is fine to get started on a hosted solution like Blogger.comor WordPress.com. They will allow you to learn the basics of blogging and web publishing without spending money. As soon as you nail down these basics, however, it is vital to buy your own domain name and to purchase a web hosting package with some company.