Solved

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

Posted on 2000-04-28
3
174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: 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

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…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

751 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