Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2000-04-28
3
Medium Priority
?
187 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 85

Accepted Solution

by:
ozo earned 300 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
Six Sigma Control Plans

916 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