Basics of Database Queries
Now that you've mastered creating a Perl script and connecting to and disconnecting from your database, you're ready to do some simple database queries.
Running Queries That Return a Resultset
DBI has a number of methods (shown in Table 12.1) that help you handle a query that returns a resultset.
Table 12.1 shows the methods for running queries, which you will learn how to use.
DBI Method | Meaning |
---|---|
$sth = $dbh->prepare ($statement); | Prepare query |
$rv = $sth->execute (); | Execute query |
$rv = $dbh->do ($statement); | Prepare and execute query, and finish |
$rv = $dbh->do ($statement, %attr); | Prepare and execute query, and finish (with extra attributes) |
Running Queries with prepare() and execute() ...
Get Sams Teach Yourself MySQL in 21 Days, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.