(RADIATOR) using the already connected DB refs

Martin Edge martinedge at kbs.net.au
Mon Oct 28 18:33:04 CST 2002


Hey Guys,

Little curious, I need to perform an Extra SQL query while processing RADIUS
requests, and set the value to an internal Radiator variable, it comes from
the same database, so I was wondering how one would utilise the existing DB
connection easily, without having to spawn an additional one using DBI.

Below is the code I'm using..

# find the POP id
sub
{
    my $p = ${$_[0]};

        my $nasip;
        my $db;

        $nasip = $p->get_attr('NAS-IP-Address');

        # If there is a NAS at all..
        if ($nasip) {
                use DBI;
                my $user = "xxxxxx";
                my $password = "xxxxxxxxx";
                my $database = "xxxxxxxxxx";

                my $dsn = "DBI:mysql:database=$database;host=192.168.3.21";
                $db = DBI->connect($dsn, $user, $password);
                if (!$db) {
                        &main::log($main::LOG_DEBUG,"Failed Bringin Up
Second DB\n".DBI::errstr);
                        return;
                }

                # get the popid
                my $popidquery = "select popid from nascache where
nasidentifier = '$nasip'";
                my $sth = $db->prepare($popidquery);
                $sth->execute;
                my $popid = ($sth->fetchrow())[0];


                if ($popid) {
                        &main::setVariable("popid", $popid);
                        &main::log($main::LOG_DEBUG,"Resolved Packet to
POPid $popid");
                } else {
                        &main::log($main::LOG_DEBUG,"No POPid for NASIP
$nasip");
                        &main::setVariable("popid", "0");
                }
}

Regards,
Martin Edge
Software/Network Engineer
KBS Internet

Phone: 1300 727 205
Web: http://www.kbs.net.au/
Extranet: http://xray.kbs.net.au/
eMail: support at kbs.net.au
-------------=-=-=-----------------

===
Archive at http://www.open.com.au/archives/radiator/
Announcements on radiator-announce at open.com.au
To unsubscribe, email 'majordomo at open.com.au' with
'unsubscribe radiator' in the body of the message.


More information about the radiator mailing list