#!/usr/local/bin/perl ########################################################################### # # mysql_connect.pl # # uses the perl DBI module # # replace and with the correct values # ########################################################################### # # set output to unbuffered and print the correct content-type # $|=1; print "Content-Type: text/html\n\n"; # # we need to use the DBI module # use DBI; # # replace and with the correct values # set up the variables to connect to the database # $user=''; $passwd=''; $dbname=''; $dsn = "DBI:mysql:$dbname"; # # this establishes the connection to the database and lets us know if it worked # print "Attempting to connect to the database...
"; $dbh = DBI->connect($dsn, $user, $passwd); if ( !defined $dbh) { print "Fatal Error!
Could not connect to database.
"; print "Database: $dbname
"; print "User: $user

"; exit 1; } else { print "Successful connection to database: $dsn
\n"; } # # generate our SQL commmand # any SQL command can go here (select, create, alter, etc) # replace with correct value # $command ="select * from
"; print "Command: $command

\n"; # # create a statement handle and prepare to execute the SQL statement # $sth = $dbh->prepare($command); if ( !defined $sth ) { print "Can't create Statement Handle Object $dbh->errstr
\n"; exit 1; } # # execute the command # $rv = $sth->execute; print "Return Code: $rv".$dbh->errstr."


\n"; exit;