You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Alexei V. Alexandrov" <av...@elcomsoft.com> on 2000/07/20 17:37:52 UTC
[DESCRIBE]: Persistent DB
Hello everyone,
I`m new to mod_perl, but still i want to learn as much as possible. I`m
currently plaing with subject. I have read the quide and here is what i have.
My perl startup file looks like this:
--------------------------------------------------------------------------------
use Apache();
use Apache::Registry;
use Apache::DBI;
use lib map { "/home/ava/$_" } qw '.lib';
use strict;
$Apache::DBI::DEBUG = 2;
Apache::DBI->connect_on_init(
"DBI:mysql:site",
"user",
"password",
{
RaiseError => 1,
PrintError => 0,
AutoCommit => 1,
}
);
Apache::DBI->setPingTimeOut("dbi:driver:download:spider", 0);
------------------------------------------------------------------------
Then i added the following lines to Apache::Registry module:
------------------------------------------------------------------------
use vars qw !$dbh!;
$dbh ||= DBI->connect("dbi:mysql:site","user","password");
------------------------------------------------------------------------
Added to .htaccess file
------------------------------------------------------------------------
PerlModule Apache::DBI
------------------------------------------------------------------------
Created a test script to check the setup:
------------------------------------------------------------------------
my $dbh = DBI->connect('dbi:mysql:site','user','password', {autocommit => 0});
my $sth = $dbh->prepare("select LevelName from Classifytable");
if ($sth->execute) {
while (my $name = $sth->fetchrow_array) {
print "$name\n";
}
}
------------------------------------------------------------------------
while starting the server i also started mysqladmin processlist in another
console to check what is going on.
18523 user ws08.hq download Sleep 176
This is when i started the server this connection went up and the number began
to increment. This means that Apache::DBI pings my connection. Am i right? Next i
started the script i have created and here we go with another connection:
18529 user ws08.hq download Sleep 6
Then another script that also uses this connection and everything works fine.
But when i tried to connect to the same database with the same options from
Embedded perl he tried to use the main apache connection and did not open a
connection itself or used other connections. It is not possible to use
persistance from embperl? Can you explain. Maybe i have mistaken something?
Sorry for such a big post and for my english.
Best regards,
Alexei V. Alexandrov [AA4460, AVA32-RIPN, AA1829-RIPE]
------------------------------------------------------------------------
*** Alexei V. Alexandrov -- www.elcomsoft.com ---- ava@elcomsoft.com ***
*** PGP Fingerprint: 9F23 7153 51D4 FD8F 4E7F D4DF E0FA E400 ***
------------------------------------------------------------------------