MySQL Basics In Pictures
Join two tables
  1. Open the text editor.
  2. Save the blank document as in the programs directory.
  3. Copy the following code and paste it into

    #!/usr/bin/perl -w
    use DBI;
    use strict;
    # database information
    my $db="us_presidents";
    my $host="localhost";
    my $port="3306";
    my $userid="marty";
    my $passwd="watch4keys";
    my $connectionInfo="DBI:mysql:database=$db;$host:$port";
    # find a random number between 1 and 20
    my $random=int(rand 20) + 1;
    # make connection to database
    my $dbh = DBI->
    # prepare and execute query
    my $query = "SELECT first,middle,last,quote
    FROM quote,name
    my $sth = $dbh->prepare($query);
    # assign fields to variables
    my ($first,$middle,$last,$quote);
    $sth->bind_columns(undef, \$first, \$middle, \$last, \$quote); 
    # output random quote
    while($sth->fetch()) {
       print header(), start_html("Random Quotation");
       print "

    Random Quotation: $quote

    - $first "; print "$middle" if ($middle); print "$last\n

    ", end_html(); } $sth->finish(); # disconnect from database $dbh->disconnect;