[ale] Perl Question

Christopher Fowler cfowler at outpostsentinel.com
Fri Jul 30 10:21:03 EDT 2004


I'm trying to abstract all my DB code inside of a perl module and have a
question


--------- Cut Here ----------
sub get_console_list {
  my($self, $ens_id) = @_;
  my @cols = ();
  my %CONSOLE = ();
  my $x = 0;
  my $sql = "select console_id, name, login, password, active, port from
console";
  if($ens_id) {
    $sql .= " where ens_id = '$ens_id'";
  }

  my $dbase = $self->{'CONNECTION'};
  my $res = $dbase->prepare($sql) or die $dbase->errstr();
  $res->execute() or die $res->errstr();
  $res->bind_columns(\$cols[0], \$cols[1], \$cols[2], \$cols[3],
\$cols[4] ,\$cols[5])
    or die $res->errstr();
  while($res->fetch()) {
    $CONSOLE{$x}{'ID'}      = $cols[0];
    $CONSOLE{$x}{'NAME'}    = $cols[1];
    $CONSOLE{$x}{'LOGIN'}     = $cols[2];
    $CONSOLE{$x}{'PASSWORD'} = $cols[3];
    $CONSOLE{$x}{'ACTIVE'}  = $cols[4];
    $CONSOLE{$x}{'PORT'}    = $cols[5];
    $x++;

  }

  return %CONSOLE;

}
--------- Cut Here -------


What I would like to do is instead of
doing $db->get_console_list(5)
I would like $db->get_console_list( 'ens_id' => 5 )
This way I can do other stuff like
$db->get_console_list ( 'ens_id' => 5 , 'active' => 'enabled');

Can someone give me a pointer on how I can do this.

Thanks
Chris




More information about the Ale mailing list