#!/usr/bin/perl -w # access_cars.pl # A CGI program to illustrate using MySQL from Perl # Get access to DBI and CGI use DBI; use CGI ":standard"; print header(); print start_html("CGI-Perl MySQL database access"); # Create the connection to the database, cars my $dbh = DBI->connect("DBI:mysql:cs655", "cs655", "abc123"); if (!$dbh) { print "Error connecting to database; $dbh->errstr\n"; } # Get the query and display it my $query = param("query"); print "
The query is: ", $query, "
"; # Build a statement object for a SELECT SQL command my $sth = $dbh->prepare($query); # Execute the statement $sth->execute or die "Error - unable to execute query: $dbh->errstr\n"; # Get a reference to the column names in the returned value and # display the column names as the first table row print "| $field_name | "; } print "
|---|
| $field | "; } print "