17.1 Introduction
When you store information in your
database, you can easily retrieve it for use on the Web in a variety
of ways. Query results can be displayed as unstructured paragraphs or
as structured elements such as lists or tables; you can display
static text or create hyperlinks. Query metadata can be useful when
formatting query results, too, such as when generating an HTML table
that displays a result set and uses its metadata to get the column
headings for the table. These tasks combine query processing with web
scripting, and are primarily a matter of properly encoding any
special characters in the results (like & or
<) and adding the appropriate HTML tags for the
types of elements you want to produce.
This chapter shows how to generate several types of web output from
query results. It also covers techniques for inserting binary data
into your database and for retrieving and transferring that kind of
information to clients. (It's easiest and most
common to work with text for creating web pages from database
content, but you can also use MySQL to help service requests for
binary data such as images, sounds, or PDF files.)
The recipes here build on the techniques shown in Chapter 16 for generating web pages from scripts and for
encoding output for display. See that chapter if you need some
background in these topics.
The scripts from which the examples in this chapter are drawn can be
found in the recipes distribution under the
directories named for the servers used to run them. For Perl, PHP,
and Python examples, look under the apache
directory. For Java (JSP) examples, look under
tomcat; you should already have installed these
in the process of setting up the mcb application
context (Recipe 16.4). The exception to this is that
some of the utility routines used here are found in library files in
the lib directory.
Note that not all languages are represented in every section. If a
particular section seems to be
"missing" an example for the
language you're interested in, check the
recipes distribution; it may contain the
implementation you want, even if it's not shown
here.
|