PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Michael Peppler <mpeppler at peppler dot org>
Subject: Re: How do I access multiple databases on multiple hosts
Date: Jul 14 1999 2:51PM

Kathy J. Doty writes:
 > What I would like to be able to do is
 > query these databases using Sybperl to obtain
 > results from some of the tables from each of these
 > databases as well as results from the database
 > I have on my own host and display them on a web page.

You need to open one connection to each of the database servers where
you need to get data. These database servers need to be listed in your 
interfaces file. 

The simplest, if you are not getting too much data from each database, 
would be something like this:

my @servers qw(SERVER1 SERVER2 SERVER3);   # use real server names :-)

my %results;
foreach (@servers) {
   my $dbh = new Sybase::CTlib $user, $pwd, $_;
   my $data = $dbh->ct_sql("select ... from ... where ...");
   $results{$_} = $data;   # remember the results for this server
}

# Now you can print out the results.

foreach (keys(%results)) {
   print "Server $_:\n";
   foreach my $row (@{$results{$_}}) {
	foreach my $col (@$row) {
	    print "$col";
        }
        print "\n";
   }
}

__END__

This stores all the results in memory, so you should only use it if
the number of rows that you are going to retrieve is relatively
small. 

The @{$results{$_}} is a little cryptic, but what it really means is:

"Take the array that is stored in %results for the key $_"

I hope that this helps a bit in stead of confusing you :-)

Michael
-- 
Michael Peppler         -||-  Data Migrations Inc.
mpeppler@peppler.org    -||-  http://www.mbay.net/~mpeppler
Int. Sybase User Group  -||-  http://www.isug.com
Sybase on Linux mailing list: ase-linux-list@isug.com