#!/usr/bin/perl use DBI; print < Example of Perl calling MySQL END # database information $db="g_sql_test_test"; # if running this from https://cgi.stanford.edu/~sunetid/cgi-bin/ $host="127.0.0.1:3308"; # or otherwise using an stunnel connection following # https://uit.stanford.edu/service/sql/configuring_stunnel $host="127.0.0.1"; # if not using a stunnel connection then use this $host # definition $host="mysqlhosting.cl.stanford.edu"; $userid="gsqltesttest"; $passwd="secret"; $connectionInfo="dbi:mysql:$db;$host"; # make connection to database $dbh = DBI->connect($connectionInfo,$userid,$passwd); # prepare and execute query $query = "SELECT * FROM test WHERE f1 = \"test3\" "; $sth = $dbh->prepare($query); $sth->execute(); # assign fields to variables $sth->bind_columns(\$f1, \$f2, \$f3, \$f4); # output name list to the browser print "f1 in the test database:

\n"; print "\n"; while($sth->fetch()) { print "
$f1$Age\n"; } print "
\n"; print "\n"; print "\n"; $sth->finish(); # disconnect from database $dbh->disconnect