#!/usr/pubsw/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/ # or otherwise using an stunnel connection $host="127.0.0.1"; # if not using a stunnel connection then use this $host # definition $host="mysql-user.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