Welcome to PCCS-Linux.COM Hello, and welcome to the PCCS-Linux Home Page.
Your last visit was !!!
Your Browser is running on Other
 
Perl DBI MySQL

Using perl, DBI::MySQL

#!/usr/bin/perl 

use DBI;
use strict;

my $dbh = DBI->connect( "dbi:mysql:perlsnmp", "root", "password") or
die("Failed to connect to Database");

my $sth = $dbh->prepare('SELECT * FROM deviceinfo WHERE sysname = ?')
   or die "Cant executer SQL statement: $DBI::errstr\n";

system('clear');

print "CTRL -C to exit\n";
print "Enter Device Host Name > ";
 while( my $sysname = <>) {

  my @data;
  chomp $sysname;
  
  $sth->execute($sysname) or die "Can't execute SQL statement:
$DBI::errstr\n";
  print "ifDescr\tifInOctets\tifOutOctets\n";
  my @row;
    while (@row = $sth->fetchrow_array( )) {
     print " @row[6]\t$row[7]\t$row[8]\n";
   }
  
  if($sth->rows == 0) {
    print "No Match for `$sysname`.\n\n";
  }

  print "\n";
  print "Enter Device Host Name > ";
}

$sth->finish;
$dbh->disconnect or warn "Error disconnecting: $DBI::errstr\n";



Page hits 39 on :11:07



This web site is prepared and maintained by Chauncey Thorn.
The information contained in this site was valid at the time of posting.
Chauncey Thorn, assumes no liability for damages incurred directly or indirectly as a result of errors, omissions or discrepancies.

Remember most of the content here are my notes...

All logos and trademarks in this site are property of their respective owner. All the rest © by PCCS-Linux.COM

PCCS-Linux.COM ::ource Advocate Articles catalogue
2000 2002