Tuesday, October 6, 2009

A Complete but Simplest Access-Perl DBI connectivity program!!




















I searched a lot for simple but complete basic DBI-Access Connectivity example in web.. and I got none..
So I created one for myself!!:)
Program is testes in WIN-XP, ActivePerl,MS-Access environment.

  1. Create a database called Data in Access.
  2. Create a table Called Data table in it with ID(AutoNumber),Name,Marks field
  3. Then fill the table with whatever appropriate values you want.
  4. Create a System DSN(Here its name is 'DSN', Give any name you want!!)by going to Control Panel->Administrative Tools->Data Sources.
  5. Execute the program

use DBI;
print "Database Retrieve";
$dbh=DBI->connect('dbi:ODBC:DSN');

print "\n\nSEE ORIGINAL DATABASE";
$see="Select * from DataTable";
$holdnew=$dbh->prepare($see);
$holdnew->execute|| die "Sorry Kanree!!";
while(@row=$holdnew->fetchrow_array)
{print("\n@row\n");}

print "\n\nNow Insert A new name NEW and 100 Marks for same name name";

$insert="INSERT into DataTable (Name,Marks) VALUES ('New','100')";
$insert_handle=$dbh->prepare($insert);
$insert_handle->execute();


print "\n\nSee Inserted DataBase";
$see="Select * from DataTable";
$holdnew=$dbh->prepare($see);
$holdnew->execute|| die "Sorry Kanree!!";
while(@row=$holdnew->fetchrow_array)
{print("\n@row\n");}


print "\n\n Let Us Update Database where ID=1 with 600";
$update="UPDATE DataTable SET Marks = '600' WHERE ID=1 ";
$update_handle=$dbh->prepare($update);
$update_handle->execute();

print "\n\nSee Updated DataBase";
$see="Select * from DataTable";
$holdnew=$dbh->prepare($see);
$holdnew->execute|| die "Sorry Kanree!!";
while(@row=$holdnew->fetchrow_array)
{print("\n@row\n");}

#end of the code:)

Have a easy learning!!:)

No comments:

Post a Comment