Solved

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

Posted on 2000-04-28
3
170 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
ID: 2760889
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
ID: 2761313
#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
ID: 2769398
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

685 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