Re: How to include a connection file in perl
- From: xhoster@xxxxxxxxx
- Date: 04 Dec 2006 01:38:58 GMT
sulata@xxxxxxxxx wrote:
Hello
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
$dbh->disconnect();
foo.pm:
package foo;
sub connect {
DBI->connect("DBI:mysql:database=perl;host=localhost",
"root", "", {'RaiseError' => 1});
}
1;
__END__
file.pl:
use foo;
my $dbh=foo::connect();
# etc.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
.
- References:
- How to include a connection file in perl
- From: sulata
- How to include a connection file in perl
- Prev by Date: Why does Tie::Simeple (scalar) work without real local data?
- Next by Date: FDF2XML skript?
- Previous by thread: How to include a connection file in perl
- Next by thread: Why does Tie::Simeple (scalar) work without real local data?
- Index(es):