On Thu, Nov 08, 2001 at 07:26:18PM -0600, Mark Browne wrote:
> I am also trying to get web <-->database thing going.
> So far I have got the web form <--->Perl part working; Yippie for CGI.
> The cgi-lib code makes this falling-off-a-log simple.
> 
> Now for the Perl<--->database part.
> I am actually working on it tonight.
> It seem that DBI is the way to go.
> If I understand this correctly it works the same for most databases.
> I downloaded it last night and am working through the documentation.
> 
> A little working sample code would be nice.

use DBI;

my $dbh = DBI->connect("dbi:mysql:<dbname>","username","password") or die $DBI::errstr;

my $sth = $dbh->prepare("select col1,col2 from table where col3 = ?");

$sth->execute('col3val');

while (my ($col1, $col2) = $sth->fetchrow_array()) {
      print "$col1: $col2\n";
}

$sth->finish();

$dbh->disconnect();

hope that helps!

-- 
  Thomas Eibner <http://thomas.eibner.dk/> DnsZone <http://dnszone.org/>
  mod_pointer <http://stderr.net/mod_pointer>