Solved

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

Posted on 2000-04-28
3
158 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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 …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

813 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

11 Experts available now in Live!

Get 1:1 Help Now