MySQL Basics In Pictures
  1. Within your home directory, navigate to the programs directory.
  2. Save the blank document as in the programs directory.

  3. Highlight the code below, copy it, then paste it into

    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";
    # make connection to database
    my $dbh = 
    # prepare and execute query
    my $query = "SELECT id,first,middle,last FROM name ORDER BY id";
    my $sth = $dbh->prepare($query);
    # assign fields to variables
    my ($id,$first,$middle,$last);
    $sth->bind_columns(undef, \$id, \$first, \$middle, \$last); 
    # output president's names listing
    print "The presidents in order:\n";
    while($sth->fetch()) {
       print "$first ";
       print "$middle " if ($middle);
       print "$last\n";
    # clean up
    # disconnect from database