Code that manipulates your data in some way
- print "ref->{'Last_name'}";
} - After you have finished with your result set, get rid of it so that you can free up
system resources. You do this by using the finish() method.
$sth->finish(); - You can continue issuing queries with your current handle. You can even
generate multiple statement handles with one database handle. When you are
completely finished using the database contained in the handle, close your
connection. You do this by calling the disconnect() method.
$dbh->disconnect();
That's all there is to it. If you take it step by step, it's an easy process. Now that you've got this part
down, look at how you can use this knowledge in the real world.
CGI, Perl, DBI, and MySQL: How They All Fit Together
Perl, because of its great string manipulation capabilities has, found itself a natural home on the Internet and
with Common Gateway Interface (CGI) programming. CGI is the environment where programs that send,
receive, and translate data from the Internet to your server operate. These programs tend to be an interface
to much larger applications and databases that need data from a Web site to perform their duties. Examples
of CGI applications are online stores, catalogs, and any other Web sites that need to dynamically generate
Web pages based on criteria presented by a user.
You may be asking yourself, "How does this all tie together?" Well, Perl is probably the best language to
use for CGI type programming. It's extremely fast and has strong string manipulating features—two
definite strong points when dealing with the Internet and HTML. The DBI is Perl's database interface. It
is easy to use and very powerful. And when it comes to databases that are suited for the Internet, no
other database comes even close to MySQL's speed and ease of use. With this great combination,
there is nothing you can't accomplish.
The best way to show you how this all works is to start with a sample and explain as you go along.
Handling Data on a Web Page
You are going to create a Web page that takes data from a form on a Web page and adds that data to the
Vendors table in the Meet_A_Geek database. To start, take a look at the Figure 14.1 to see what the HTML
form you will be using looks like. The form has all the fields you need to collect for the database. In a CGI
type program, the fields from this form will be passed to the Web server, along with the request for the next
page. The HTML