473,396 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

MS Access From Perl

Anyone know how I can access a MS Access database from perl?

Any help appreciated.
Nov 13 '05 #1
3 3269

"Mike S" <th******@aol.com> wrote in message
news:0M**********************@news4.srv.hcvlny.cv. net...
Anyone know how I can access a MS Access database from perl?

Any help appreciated.


Wrong newsgroup, moron.
Join here:
ac***********@hotmail.com

Nov 13 '05 #2
gj
Mike S wrote:
Anyone know how I can access a MS Access database from perl?

Any help appreciated.


A quick google
(http://www.google.com/search?sourcei...soft+access%22)
found the following script at
http://hypernews.ngdc.noaa.gov/Hyper...16.html?nogifs

I dont know perl myself so I cannot attest to its validity.

<<script begins>>

use Win32::ODBC;

$DEBUG = 0;

$DriverType = "Microsoft Access Driver (*.mdb)";
$DSN = "Win32 ODBC --MAOmaoMAOmaoMAO--";
$Dir = "c:\\mydocu~1";
$DBase = "maotest.mdb";

# Change Field1 and Field2 of Record 1 (i.e., where first column of
table equals 1)
$primaryID = 1;
$newvalue[$primaryID] =
{(
"Field1" => "test Field1",
"Field2" => "test Field2",
)};

Win32::ODBC::ConfigDSN(ODBC_ADD_DSN, $DriverType,
("DSN=$DSN", "Description=MAO Win32 ODBC Test DSN for Perl",
"DBQ=$Dir\\$DBase", "DEFAULTDIR=$Dir", "UID=", "PWD="))
or die "ConfigDSN(): Could not add temporary DSN" .
Win32::ODBC::Error();

$db=new Win32::ODBC($DSN) or die "couldn't ODBC $DSN because ",
Win32::ODBC::Error(), "\n";

my(%data, $key) = $db->GetDSN();
foreach $key (keys %data) {
print "$key: <$data{$key}>\n";
}

# Get list of tables in database
@table = $db->TableList;
print "Tables: @table\n" if $DEBUG;

$query = "select * from $table[0]";
!$db->Sql($query) or die "couldn't do $query because ", $db->Error(), "\n";

# Get list of columns in first table of database
@column = $db->FieldNames();
print "Columns: @column\n" if $DEBUG;

# Check for typos in hard-coded column names in $newvalue above

for $thisvalue (@newvalue)
{
$J = ' ';
$searchin = $J.join($J, @column).$J;
for $name (keys %$thisvalue)
{
$searchfor = $J.$name.$J;

print "Looking for \"$searchfor\" in \"$searchin\"\n"
if $DEBUG;
$searchin =~ /$searchfor/ or die "Can't locate $name in
@column";
}
}

print "Before...\n";
&PrintDatabase($db);

$query = "update $table[0] set
$column[1]=\'$newvalue[$primaryID]{$column[1]}\',
$column[2]=\'$newvalue[$primaryID]{$column[2]}\' where
$column[0]=$primaryID";
!$db->Sql($query) or die "couldn't do $query because ", $db->Error(), "\n";

$query = "select * from $table[0]";
!$db->Sql($query) or die "couldn't do $query because ", $db->Error(), "\n";

print "After...\n";
&PrintDatabase($db);

Win32::ODBC::ConfigDSN(ODBC_REMOVE_DSN, $DriverType, "DSN=$DSN") or die
"ConfigDSN(): Could not remove temporary DSN because ",
Win32::ODBC::Error();

sub PrintDatabase
{
my $db = shift(@_);
my @table = $db->TableList;
my @column;
my $column;
my $query = "select * from $table[0]";

!$db->Sql($query) or die "couldn't do $query because ", $db->Error(), "\n";
@column = $db->FieldNames();

for $column (@column)
{
printf("%15.15s ", $column);
}

print "\n";

for $column (@column)
{
printf("%15.15s ",
"_________________________________________________ ______________________________");
}

print "\n";

while($db->FetchRow())
{
my %Data = $db->DataHash();
for $column (@column)
{
printf("%15.15s ", $Data{$column});
}

print "\n";
}

print "\n";
<<script ends>>
Nov 13 '05 #3
Mike S wrote:
Anyone know how I can access a MS Access database from perl?

Any help appreciated.


Sure. Use the DBI package. Driver for ADO available here:
http://search.cpan.org/search?query=...3A&mode=module

Same chapter on DBI:
http://www.oreilly.com/catalog/perld...pter/ch04.html

DBI Home Page:
http://dbi.perl.org/

--
'-------------------------------
' John Mishefske
'-------------------------------

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gary | last post by:
Has anyone tried to use perl on a linux system to access an ms-access database? I can't seem to get clear info on where this is even possible. I did read that you can use a perl proxy on both...
1
by: Mike_red | last post by:
Hello, I hope someone can solve my problem here. I am currently working/programming a website using Debian Linux + Perl + PHP + PostgreSQL + Apache. Some data in the postgreSQL server must...
2
by: moller | last post by:
Im looking in to the possibility of moving from mySQL to an access database. My reasons are: (1) Database is single user. (2) Database local on users PC. (3) Database has only 8 tables where 4...
2
by: skeize | last post by:
I'm new to Perl, but not new to Access. I want to hit an Access db with a perl script, and I am looking for good online resources, can anyone help me out? Thanks, Pat
6
by: Serious_Practitioner | last post by:
Good day all, and thank you in advance for your help. No - MANY thanks in advance for your help - I know nothing about using databases on Web servers. I am about to discuss a project with a...
6
by: Doomster | last post by:
In a previous job, we had Perl scripts which could interact with a SQL DB using Perl's DBI module We were able to programmatically add, delete and query tables using this module. Is it possible...
4
by: Patricia Mindanao | last post by:
I want to call cgi perl scripts on my web hosters server from my HTML web pages (on the the web hosters server too). It occurs sometimes (especially during development phase) that these cgi-perl...
2
by: kcddoorman | last post by:
I'm am completely new to the world of Perl. It looks like a cross between C and linux scripting. I have some experience in both linux and C, but I'm using perl to query an Access database and post...
3
by: Max58kl | last post by:
Trying to access data and print it to the screen using Perl Builders I/O Window -------------------------------------------------------------------------------- Hi I am using a program called...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.