|
|
sybperl-l Archive
Up Prev Next
From: Michael Peppler <mpeppler at MBAY dot NET>
Subject: Can someone share a web page/cgi/sybperl script to work with
sybase?
Date: Dec 2 1998 10:20PM
Roleigh Martin writes:
> While I am awaiting the above (did I leave anything out?), could
> someone please show me everything that would be required to show
> a web page that shows nothing but the results of doing the
> following task (using something that exists in everybody's Sybase
> database):
>
> select suid, uid, gid, name from sysusers
>
> [then from the list that is generated, allowing the user to
> highlight one line, press double-click with the mouse, and
> to have the CGI script execute the following (pretend the user
> highlights the line that shows "dbo")]
>
> select suid, name, environment=substring(environ,1,25) from
> sysusers where name = 'dbo'
>
> If I could see how the above is done, I could finish my task very
> fast--the above would be a fantastic example program.
Here's one way - thrown together in about the time it takes to type it
in...
Michael
--
Michael Peppler -||- Data Migrations Inc.
mpeppler@mbay.net -||- http://www.mbay.net/~mpeppler
Int. Sybase User Group -||- http://www.isug.com
Sybase on Linux mailing list: ase-linux-list@isug.com
#!/usr/local/bin/perl -w
use strict;
use Sybase::DBlib;
use CGI;
my $query = new CGI;
my $state = $query->param('__state') || 0; # default to 0
my $dbh = new Sybase::DBlib 'sa';
print $query->header;
print $query->start_html(title=>'Sysusers Query');
if($state == 0) {
print "A little sysusers query...";
my $data = $dbh->sql("select suid, uid, gid, name from sysusers", undef, TRUE);
# print $query->start_form;
print "\n";
my $first = 1;
foreach my $row (@$data) {
if($first) {
print "\n";
foreach (sort keys(%$row)) {
print "| $_ | ";
}
print " \n";
$first = 0;
}
print "\n";
foreach (sort keys(%$row)) {
if($_ eq 'name') {
print "| {name}>$row->{$_} | ";
} else {
print "$row->{$_} | ";
}
}
print " \n";
}
print " \n";
} elsif($state == 1) {
my $name = $query->param('name');
my $data = $dbh->sql("select suid, name, environ from sysusers where name='$name'");
print "Results:";
print "\n";
foreach my $row (@$data) {
print "\n";
foreach (@$row) {
print "| $_ | \n";
}
print " \n";
}
print " \n";
}
print $query->end_html;
|