Pushing Query Results to an Array to Find Wildcard Hosts : MySql « Database « Perl






Pushing Query Results to an Array to Find Wildcard Hosts

   


#!/usr/bin/perl

use DBI;
use strict;

my $username = "dbuser";
my $password = "dbpassword";
my $dsn = "dbi:mysql:mysql:192.168.1.10";
my $dbh = DBI->connect($dsn,$username,$password) or die "Cannot connect to database: $DBI::errstr";

my $sth = $dbh->prepare("SELECT host FROM mysql.user");

$sth->execute() or die "Cannot execute sth: $DBI::errstr";

my @mysqlhosts;
while (my $hostname = $sth->fetchrow_array()) {
   push (@mysqlhosts,$hostname);
}

while (<@mysqlhosts>) {
    if ($_ =~ /%/) {
        print "Wildcard host found: $_\n";
    }
}
$dbh->disconnect();

   
    
    
  








Related examples in the same category

1.Deleting Entries
2.Dumping a Query's Results
3.Error Diagnostic Variables
4.Handling Quotes
5.Inserting into a Database
6.Load text file to database
7.MySQL Data Types
8.Preparing a Statement Handle and Fetching Results
9.Query parameter binding
10.Retrieving Query Results Listing MySQL Users and Hosts
11.Retrieving an Index ID