[prev in list] [next in list] [prev in thread] [next in thread]
List: apache-modperl
Subject: Newbie Q: DBI persistent connection test
From: Frank Smith <frank_smith () hotmail ! com>
Date: 1999-05-30 22:14:24
[Download RAW message or body]
Hi,
I installed Apache, mod_perl. MySQL on Linux. And I want to test whether I
am using persistent connection. My basic idea is to print the $dbh each
time and see where they are the same. Following is the code:
_______________________________________________________________
#file: TestDBI.pl
use strict;
use DBI;
use constant DSN => 'DBI:mysql:testdb';
use constant DB_USER => 'test';
use constant DB_PASSWD => 'test';
my $dbh1 = DBI->connect(DSN,DB_USER,DB_PASSWD) ;
my $strSQL = qq{SELECT * FROM mytable);
my $sth1 = $dbh->prepare($strSQL);
$sth1->execute();
print ("DBH1--> $dbh1 \n");
$sth1->finish();
$dbh1->disconnect();
my $dbh2 = DBI->connect(DSN,DB_USER,DB_PASSWD);
my $dbistring2=$dbh2;
print ("DBH2stirng --> $dbistring2 \n");
$dbh2->disconnect();
________________________________________________
I run this program by brower ( http://mylinux/cgi-bin/TestDBI.pl ). and
[reload] several time. Following is the result:
1st time)
DBH1--> DBI::db=HASH(0x82b2260)
DBH2stirng --> DBI::db=HASH(0x82b59f8)
2nd time)
DBH1--> DBI::db=HASH(0x82b2344)
DBH2stirng --> DBI::db=HASH(0x82b59bc)
3rd time)
DBH1--> DBI::db=HASH(0x82b238c)
DBH2stirng --> DBI::db=HASH(0x82b5a7c)
4th time)
<same as 2nd time>
5th time)
DBH--> DBI::db=HASH(0x82b2354)
DBH2stirng --> DBI::db=HASH(0x82b5a44)
6th time)
<same as 2nd time>
So according to the result, is that correct that the 2nd, 4th, 6th reload
are using the same connection and others are not ?
Or they are all using the same connection but I cannot prove it by printing
out $dbh ?
Thanks in advance
frank
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic