Ananda has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I intend to know how a connection to database be established , such that multiple access to the database is possible. Can I store the data records in variables in perl file .(something similar to storing recordsets in jave). Are any packages available for establishing the database connectivity? Thanks and Regards Anandatirtha

Replies are listed 'Best First'.
Re: Establish database connection
by Zaxo (Archbishop) on Oct 13, 2002 at 06:24 UTC

    See DBI. It is a very complete and fluent interface to a large number of specific database drivers.

    After Compline,
    Zaxo

Re: Establish database connection
by LTjake (Prior) on Oct 13, 2002 at 13:04 UTC
    There's also some great information in the tutorials section.

    The DBI Docs provide a great reference.

    --
    Rock is dead. Long live paper and scissors!
Re: Establish database connection
by AcidHawk (Vicar) on Oct 13, 2002 at 18:27 UTC

    Please excuse the lack of

    use strict; use warnings;

    but this is some very old code I found on my machine which I slapped together to test connectivity to a MSSQL database via ODBC and did an update. I can cry when I see this code.

    #! perl.exe #Needed for ODBC access to MSSql Database use DBI; use DBD::ODBC; $dbh = DBI->connect("dbi:ODBC:driver={SQL Server};server=SERVERNAME;da +tabase=DBNAME;uid=sa;pwd=;"); my $srv = $ARGV[0]; my $new_call_num = $ARGV[1]; $idComputer = &Get_id($srv); &Update($idComputer,$new_call_num); exit(); ##Subroutines sub Get_id { $sth = $dbh->prepare("select idComputer from Computer where Name l +ike '$srv'"); $sth->execute; $id = $sth->fetchrow; print "The Computer ID for $srv is $id\n"; return ($id); } sub Update { print "Update $idComputer with $new_call_num\n"; $sql = "update Alert set CustomField1 = ? where (idComputer like ' +$idComputer')"; $sth1 = $dbh->prepare($sql) || die $dbh->errstr; $sth1->execute($new_call_num) || die $dbh->errstr; return 1; }

    Update:When I see this I realise just how much I have learned here at perlmonks. Perhaps I should re-write this code and re-post it.. I'll see at work on Monday morning..;)
    -----
    Of all the things I've lost in my life, its my mind I miss the most.