How to include a connection file in perl

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


I am shifting from php to perl and I need some help. I want to make a
database insert page and divide that page into two parts. One is the
connection file and other is the execution file. When all the following
code is in one file, it works well, but when I break it into two files,
this code does not run. Can anyone please help? Maybe I am not using
'require' properly. My code is;

# load module
use DBI;
# connect
my $dbh = DBI->connect("DBI:mysql:database=perl;host=localhost",
"root", "", {'RaiseError' => 1});
$dept_name = time();
# execute INSERT query
my $rows = $dbh->do("INSERT INTO departments (dept_name) VALUES
('".$dept_name."')") or die "Error";
print "Content-type: text/html\n\n";
print "Done: $rows row(s) affected\n";
# clean up

Re: How to include a connection file in perl wrote:
Quoted text here. Click to load it
package foo;
sub connect {
               "root", "", {'RaiseError' => 1});
use foo;
my $dbh=foo::connect();
# etc.


-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB

Site Timeline