Creating a Web Page Integrated with SQL Data : select « Database « Perl

Home
Perl
1.Array
2.CGI
3.Class
4.Data Type
5.Database
6.File
7.GUI
8.Hash
9.Language Basics
10.Network
11.Regular Expression
12.Report
13.Statement
14.String
15.Subroutine
16.System Functions
17.Win32
18.XML
Perl » Database » select 
Creating a Web Page Integrated with SQL Data
   


#!/usr/bin/perl

use DBI;
use strict;
use CGI qw/:standard/;

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

my $hosttolookup = "%";

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

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

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

print header,
      start_html('MySQL Hosts Using Wildcards');

my $count = @mysqlhosts;
if ($count == 0) {
    print p("No Hosts Using Wildcards");
}
else {
    while (<@mysqlhosts>) {
        print p("Host Wildcard: $_");
    }
}
print end_html;

$dbh->disconnect();

   
    
    
  
Related examples in the same category
1.Select, Execute, and Dump the Results
2.Select, Execute, and Fetch a Row as a Hash
3.Select, Execute, and Fetch a Row as an Array
4.Simple query
5.The First SQL Query
6.Using a Placeholder
7.Creating an HTML Table
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.