You are Here: FAQ ->Scripting & Programming->Perl->Article #2


WebHosting 5.0 This article is for 1&1 Linux WebHosting only.


Access to the MySQL data base with Perl



With the module DBI the following Perl script realises a data base access:

Script 1: database.pl

#!/usr/bin/perl
use DBI;
print "Content-type:text/html\n\n";

$db_handle = DBI->connect("dbi:mysql:database=dbxxxxxxxx;host=dbxxx.oneandone.co.uk;user=dboxxxxxxxx;password=xxxxxxxx")
    or die "Couldn't connect to database: $DBI::errstr\n";

    $sql = "SELECT * FROM puretest";
    $statement = $db_handle->prepare($sql)
    or die "Couldn't prepare query '$sql': $DBI::errstr\n";

    $statement->execute()
    or die "Couldn't execute query '$sql': $DBI::errstr\n";
    while ($row_ref = $statement->fetchrow_hashref())
          {
              print "Name <b>$row_ref->{name}</b> has e-mail address::<b>$row_ref->{email}</b>.<br>";
           }

    $db_handle->disconnect();




Print Article
How useful was this article?
(From 5 = Very Useful to 1 = Not Very Useful at all):
1 2 3 4 5