#!/usr/bin/perl # this is a perl program to access MySQL database # using a SQL statment. this was created and tested on Linux. use CGI; use DBI; my $db = 'DBI:mysql:people:localhost'; my $username = 'accc'; my $pass = 'password'; my $dbh = DBI->connect($db, $username, $pass); my $location = 'England'; my $sex = 'Female'; my $sql = qq{ SELECT * FROM names WHERE location = ? AND sex = ? }; my $sth = $dbh->prepare($sql); $sth->execute($location, $sex); while(%array = $sth->fetchrow_hashref) { print "$array{'name'} is $sex, aged $array{'age'} and from $location"; } $sth->finish; $dbh->disconnect(); exit;