davis has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use Apache::Registry; use Apache::DBI; use lib "."; use Bar; use CGI::Carp qw(fatalsToBrowser); use CGI qw(:standard -no_xhtml); my $q = new CGI; $q->default_dtd('-//W3C//DTD HTML 4.0 Transitional//EN'); my $order_by = param("order_by") || "part_no"; print header(-expires=>"-1d"); print start_html(-title=>"Test"); if(exists $ENV{"MOD_PERL"}) { print "Running under mod_perl<br>"; } else { print "<b>Not</b> Running under mod_perl<br>"; } print start_form; print popup_menu(-name=>"order_by", -values=>["column1", "column2", "c +olumn3", "column4"]); print submit; print end_form; Bar->get_top_level_kit($order_by); print end_html; Bar->close;
package Bar; use strict; use Apache::Registry; use Apache::DBI; use DBI; use Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT = qw(get_top_level close); @EXPORT_OK = qw(); %EXPORT_TAGS = (); my $dbname = "name"; my $dbuser = "user"; my $dbpass = "pass"; my $dbhost = "localhost"; my $dbport = 3306; my $dsn = "DBI:mysql:database=$dbname;host=$dbhost;port=$dbport"; our $db = DBI->connect($dsn, $dbuser, $dbpass) or die "Couldn't connect to the database: $!\n"; sub get_top_level_kit { my ($package, $order_by) = @_; print $order_by; my $top_level_query = "SELECT row_id FROM table WHERE other +_column=0 ORDER BY ?"; my $top_level_sth = $db->prepare($top_level_query); $top_level_sth->execute($order_by) or die "Unable to execute $top_level_query: " . $top_l +evel_sth->errstr . "\n"; while(my @current = $top_level_sth->fetchrow_array) { print "Got: $current[0]<br>\n"; } $top_level_sth->finish(); } sub close { $db->disconnect; } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI ignores value selected by CGI
by busunsl (Vicar) on Jan 10, 2002 at 16:08 UTC | |
by tomhukins (Curate) on Jan 10, 2002 at 16:34 UTC | |
by davis (Vicar) on Jan 10, 2002 at 16:35 UTC | |
|
Re: DBI ignores value selected by CGI
by runrig (Abbot) on Jan 10, 2002 at 22:19 UTC |