#!/local/bin/perl5 # Chris Wilson use DBI; use CGI; #-- the line below will dump the errors to the browser. use CGI::Carp qw/fatalsToBrowser/; # --- begin parameters --- $ENV{INFORMIXDIR} = '/local/apps/informix'; $ENV{INFORMIXSERVER} = 'onlintli'; #$ENV{INFORMIXSQLHOSTS} = '/local/apps/informix/etc/sqlhosts'; # "my" is a keyword for local variable. my $data_source = "dbi:Informix:stores7"; my $username = "cwilson"; my $password = "*******"; # --- end parameters --- my $myquery = new CGI(); print $myquery->header(); #this is a subroutine call. You may name your function whatever you want. &getThemAll; print $myquery->end_html(); #we are done. exit; #----------------- now we go to getThemAll()------------- sub getThemAll{ #-- Here again we are declaring all the local variables. # $sql is your SQL query. # $dbh this is what is called database handle. # $cursor same as embedded sql in c you need a cursor to get the stuff from the database. # $row this is an array that you get back from the query. my ( $sql,$dbh,$cursor,@row); print $myquery->start_html(-title=>'stores7 sample query', -BGCOLOR=>'yellow'); print '

'; print("0. Drivers:\n"); my @drivers = DBI->available_drivers; print @drivers; print '


'; print ("1. The following query is to be executed:\n"); $sql = " SELECT manu_code, manu_name FROM manufact"; print("

\n", $sql, "\n\n"); print '


'; print '
'; print("\nDatasource: $data_source\n\n"); print '


'; $dbh = DBI->connect($data_source, $username, $password, { AutoCommit => 1, PrintError => 1 }) or die "Can't connect: $DBI::errstr\n"; print("

\n"); print("2. We appear to have connected.\n"); print '


'; $cursor = $dbh->prepare($sql) or die "Can't prepare SQL statement: $DBI::errstr\n"; $cursor->execute; print("\n\n"; }