Using a MS Access Database?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashokbio
    New Member
    • Jul 2007
    • 14

    Using a MS Access Database?

    Does PERL supports MS Access database?
  • miller
    Recognized Expert Top Contributor
    • Oct 2006
    • 1086

    #2
    You have posted your question under Perl Articles instead of the Perl Forum.
    I have moved it across for you.

    - MODERATOR

    Comment

    • numberwhun
      Recognized Expert Moderator Specialist
      • May 2007
      • 3467

      #3
      Originally posted by ashokbio
      Does PERL supports MS Access database?
      Why yes, yes it does. In fact, Perl supports many databases, including flatfile type db's.

      You will want to have a read of the DBI module description on CPAN. DBI is the module that interfaces with all of the popular databases, simplifying your interaction with the DB you wish to use.

      Regards,

      Jeff

      Comment

      • crazy4perl
        New Member
        • Aug 2007
        • 20

        #4
        yes it supports... see the following code for reference...

        [CODE=perl]
        use DBI;

        use strict;
        use warnings;

        ############### ############### #########
        # Script Parameters
        ############### ############### #########

        my $raj = $ARGV[0];

        ############### ############### #########
        # open connection to Access database
        ############### ############### #########

        my $dbh = DBI->connect('dbi:O DBC:driver=micr osoft access driver (*.mdb); dbq=C:\pp\emp.m db')
        or die "Cannot connect: $DBI::errstr";

        #prepare and execute SQL statement

        my $rsth = $dbh->prepare(qq{SEL ECT emp.emp_id, emp.name, emp.designation , emp.start_date FROM emp});
        $rsth->execute or die $dbh->errstr;

        my ($emp_id, $name, $designation, $start_date); # Declare columns
        $rsth->bind_columns(\ $emp_id, \$name, \$designation, \$start_date);
        [/CODE]
        Last edited by miller; Aug 11 '07, 07:28 PM. Reason: Code Tag and ReFormatting

        Comment

        • miller
          Recognized Expert Top Contributor
          • Oct 2006
          • 1086

          #5
          Greetings crazy4perl,

          Thank you for sharing your code to connect to a MS Access Database.

          Please note that I've cleaned up your syntax and formatting some for you. Specifically, take note of the use of $dbh->errstr in the error conditions now. This is typically how one gets detailed information on a DBI error. Also, the line at the beginning should be "use strict;" and not "use STRICT;".

          Kudos,
          - Miller

          Comment

          Working...