Database Reference
In-Depth Information
Figure 15.9
An error has occurred.
All that you can tell from the screen in Figure 15.9 is that something has gone wrong. Perl
itself is not as easy to use when errors occur as some of the other systems we have used in
this topic, and so to get some feedback we have to do some work as a programmer. First we
have to redirect any errors that may be generated back to the standard output stream as fol-
lows:
BEGIN {
$| = 1;
open (STDERR, “>&STDOUT”);
}
Next we have to output an error after a command that may contain an error has exe-
cuted. The DBI has an option to do this by using the following code after the connect()
function before the semicolon:
or die “\n\nConnect Error: “ . $dbh->errstr;
This forces the processing of the script to stop if an error is encountered. You can send a
message to the error stream at this time and include the actual error message using the
errstr command.
Reformatting the Output
While we are modifying this script we will tidy up the output of the query slightly by put-
ting the results in a table as follows:
print “<TABLE border=1>”;
print “<TR><TD>Date Accessed</TD><TD>Page Title:</TD><TD>IP
Number</TD></TR>”;
while (@myarray = $sth->fetchrow_array()) {
my $pagetitle = $myarray[0];
Search WWH ::




Custom Search