comexos has asked for the wisdom of the Perl Monks concerning the following question:
file index.cgi:package Database; use strict; use warnings; # with or without use Apache::DBI; the result is the same # i also load Apache::DBI in the startup.pl file... use DBI; use DBD::mysql; our (@EXPORT, $dbh); use base qw/Exporter/; @EXPORT = qw($dbh); #BEGIN { print "Content-Type: text/html\n\n"; print "\nopening db connection!\n"; $dbh = DBI->connect('DBI:mysql:dbname', 'user', 'pwd'); #} END { $dbh->disconnect; print "\nshutting down db-conn!\n"; #should not happen... } 1;
-----#!/usr/bin/perl -w use strict; use warnings; use CGI; use Database; print "Content-type: text/html\n\n"; my $q = new CGI; my %params = $q->Vars; my $userid = delete $params{USER}; my $user = $dbh->selectrow_array("select NAME from USER where ID=?", u +ndef, $userid); print "name of the user: $user!";
Edited: ~Tue Jan 14 20:13:10 2003 (GMT) by footpad: Retitled and moved to SOPW, per Consideration
|
|---|