Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

How to link Ms-access data's in perl

by Anonymous Monk
on Apr 05, 2005 at 05:11 UTC ( #444859=perlquestion: print w/replies, xml ) Need Help??

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

Hi monks,

I have a database in ms-access. Inspite of getting input from text file i having the data's in database. so, please help me the code, how to get the data's from ms-acess to perl.
Thanks in advance.

Replies are listed 'Best First'.
Re: How to link Ms-access data's in perl
by monkfan (Curate) on Apr 05, 2005 at 05:35 UTC
    Try this.
    #Windows-based Perl/DBI/MS Access example use DBI; #open connection to Access database $dbh = DBI->connect('dbi:ODBC:Clients'); #prepare and execute SQL statement #note that the query ClientName etc below is just the example # suit it with your own requirement $sqlstatement="SELECT ClientName,ClientEmail FROM billing"; $sth = $dbh->prepare($sqlstatement); $sth->execute || die "Could not execute SQL statement ... maybe invalid?"; #output database results while (@row=$sth->fetchrow_array) { print "@row\n" }
    If Microsoft Access is open and running while you try to execute these Perl scripts you may run into resource conflicts. If so, simply shutdown Microsoft Access before using Perl.

    For further info read DBI module, besides searching the wealth of Perlmonks is always useful.


      ADO supposedly works great:

      my $db_file = 'd:\path\to\database.mdb'; my $db_user = 'username'; my $db_passwd = 'pasword'; my $dbh = DBI->connect( 'dbi:ADO:Provider=Microsoft.Jet.OLEDB.4.0;Data Source='.$db_file, $db_user, $db_passwd ) or die $DBI::errstr; ...

      It bypasses ODBC which ends up connecting to the Jet Engine anyway. It also saves you from creating ODBC DSNs in the Control Panel. (yeah, I suppose you could use DSN-less ODBC connection, but people don't seem to do that for some reason.)

      Update: oops, this was supposed to be a reply to the OP.

Re: How to link Ms-access data's in perl
by gube (Parson) on Apr 05, 2005 at 07:23 UTC

    Hi try this,

    Before doing this install DBD-ODBC module in your system. Add database in ODBC before run this perl code

    use DBI; # MAPDSN is database name $dbh = DBI->connect('dbi:ODBC:MAPDSN'); #pii is table name $access="SELECT aid,piino FROM pii"; $sth = $dbh->prepare($access); $sth->execute(); while (@row=$sth->fetchrow_array) { $pii = $row[0]; $pii1 = $row[1]; $pii{$pii}=$pii1; }

Re: How to link Ms-access data's in perl
by simon.proctor (Vicar) on Apr 05, 2005 at 08:52 UTC
Re: How to link Ms-access data's in perl
by Robertn (Hermit) on Apr 06, 2005 at 06:32 UTC
Re: How to link Ms-access data's in perl
by richardX (Pilgrim) on Apr 06, 2005 at 10:41 UTC
    One tip for making large strings and memo fields work better with Access is to use the following code:
    my $dbh = DBI->connect( "dbi:ODBC:home", "", "", {RaiseError => 1, PrintError => 1, AutoCommit => 1} ) or die "Unable to connect: " . $DBI::errstr . "\n"; $dbh->{LongReadLen} = 20000 ; # to better handle long variables


    There are three types of people in this world, those that can count and those that cannot. Anon

Re: How to link Ms-access data's in perl
by bfdi533 (Friar) on Jan 19, 2018 at 17:56 UTC

    These solutions all seem to point to running and accessing the DB file on a Windows system.

    Is there a solution for Linux PERL can use to read/write MS Access DB files?

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://444859]
Approved by monkfan
Front-paged by monkfan
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2022-05-24 12:59 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (82 votes). Check out past polls.