Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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.

Comment on How to link Ms-access data's in perl
Re: How to link Ms-access data's in perl
by monkfan (Curate) on Apr 05, 2005 at 05:35 UTC
    Hi,
    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.

    Regards,
    Edward

      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; }

    Regards,
    Gube.
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

    Richard

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2014-07-24 06:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (158 votes), past polls