Solved

Connecting to a database( OZO OR ANYONE ELSE CAN U HELP)????

Posted on 2000-04-28
3
143 Views
Last Modified: 2010-03-05
HERE IS MY CODE AND I BASICALLY WANT TO CONNECT TO A DATABASE AND I WANT TO KNOW IF I AM DOING IT CORRECTLY.
-============================-============-===========

#######################################################################
#Opening the Config file for input and parsing the file inorder
#to extract the database file(s)
#######################################################################

$counter = 0;
open(DBFILE, "RC_config");
while ($line = <DBFILE>)
{
  chomp($line);
  @all = split(/,/, $line);
  $db_file_name[$counter] = $all[2]; #extracted db name
  $db_user_name[$counter] = $all[3]; #extracted user name
  $db_passwd[$counter] = $all[4];    #extracted password
  $counter++;
}
close(DBFILE);
print @db_file_name;  #debug
print @db_user_name;  #debug
print @db_passwd;     #debug

#######################################################################
#Opening all the database(S) specified in the config file and if
#any of the files do not exist, it create it.
#######################################################################
#
#for ($db_file_name[$counter])  # or for(@db_file_name)
#{
#  #OPEN IN, "<$_" or die "can't open $_ for input because $!";
#  #open %DATABASE onto the databases in config file
#  dbmopen(%DATABASES, "$db_file_name", 0666);  
#}
#
#####################################################################################
#Connecting to all the databases specified in the config file
#####################################################################################

for (@db_file_name, @db_user_name, @db_passwd)
{
  $database_handle = DBI->connect(dbi:SQL:"$db_file_name","db_user_name","db_passwd");
}


QUEST:: IS MY FOR LOOP CORRECT?  I WANT IT TO CONNECT USING THE RIGHT INFO THAT I EXTRACTED FROM EACH LINE OF MY CONFIG FILE. OR WILL THIS BETTER CAPTURE WHAT I WANT TO DO
for (@a)
{
  for (@b)
  {
     .....
  }
}

THANKS ALOT.

CODER '00
0
Comment
Question by:CODER
  • 2
3 Comments
 

Author Comment

by:CODER
Comment Utility
here is how the config file looks like

dd,www.rrr.com,file1,pcollins,wxr7475
dd,www.rrr.com,file2,sdollins,wxr5882

so i have extracted the db file name, user name and passwd so i need to connect to the dbname(file 1 and file 2)  so how should i code my foreach stmt??????????

THANKS.
0
 
LVL 84

Accepted Solution

by:
ozo earned 75 total points
Comment Utility
#you can say
for( 0..$#db_file_name ){
  $database_handle = DBI->connect($db_file_name[$_],$db_user_name[$_],$db_passwd[$});
}
#or
while( <DBFILE> ){
    chomp;
    @all = split/,/;
    $database_handle = DBI->connect(@all[2,3,4]);            }
0
 

Author Comment

by:CODER
Comment Utility
Hey Ozo THANXs a million...
by the way i figured out how to create a table.
so i am getting to knowthis perl stuff a little bit....  i have another quest. thou.. i posted it...
on STRINGS..--pattern match.---extracting a particular string...

thanks again!!!!!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now