Database Reference
In-Depth Information
Figure 15.8
Perl has successfully retrieved MySQL data.
So here is the complete script which can be seen running in Figure 15.8:
#!perl
use DBI;
print “Content-type: text/html\n\n”;
print “<HTML><TITLE>mytest.pl</TITLE><body>\n”;
my $dbh = DBI->connect('DBI:mysqlPP:mysqlfast:host=localhost',
phpuser,abominable);
my $sth = $dbh->prepare('SELECT title, datecreated, ipnumber from webpage,log
WHERE log.webpageid=webpage.id');
$sth->execute() || quit();
while (@myarray = $sth->fetchrow_array()) {
my $pagetitle = $myarray[0];
my $ipnumber = $myarray[1];
my $datecreated = $myarray[2];
print “$datecreated $pagetitle $ipnumber<BR>\n”;
}
print”<HR>Ok”;
print”</BODY></HTML>\n”;
Coping with Errors
If you have typed the script in and tested it, you will hopefully see the screen shown in
Figure 15.8. If you have made a typing error, you may have a screen as shown in Figure 15.9.
If your code is working correctly but you want to try and break the code, try changing the
password in the connect string and trying again.
Search WWH ::




Custom Search