Apache::DBI

Apache::DBI

am 02.08.2011 15:30:28 von Feng He

Hi,

I just want to develop a modperl application.
It's a handler, the database is Mysql.
Shall I use Apache::DBI, or DBI is just fine ?

Thank u.
Regards.

Re: Apache::DBI

am 02.08.2011 16:34:04 von torsten.foertsch

On Tuesday, 02 August 2011 15:30:28 Feng He wrote:
> I just want to develop a modperl application.
> It's a handler, the database is Mysql.
> Shall I use Apache::DBI, or DBI is just fine ?

It depends. Apache::DBI provides a transparent connection cache. You can=20
forget the DB handle acquired at some time at the end of the request. The=20
next DBI::connect will then fetch the handle from the Apache::DBI cache.

On the other hand, all modern DBI versions have connect_cached() (only=20
ancient version lack this function) which provides much the same=20
functionality.

=46urther, applications that are implemented as modperl handlers often tend=
=20
to use a singleton to store the DBI handle. In this case Apache::DBI is=20
not necessary. However, in this scenario you'll have to take care of=20
cases when the connection is dropped unexpectedly. Nevertheless, I'd=20
prefer this strategy for new development because it gives you maximum=20
control over what is going on. But that's just my humble opinion.

Torsten Förtsch

=2D-=20
Need professional modperl support? Hire me! (http://foertsch.name)

Like fantasy? http://kabatinte.net

Re: Apache::DBI

am 02.08.2011 18:49:04 von david

--Apple-Mail=_A609F58D-B2EF-4122-A8C9-A284602BEAC3
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=us-ascii

On Aug 2, 2011, at 6:30 AM, Feng He wrote:

> I just want to develop a modperl application.
> It's a handler, the database is Mysql.
> Shall I use Apache::DBI, or DBI is just fine ?

I recommend DBIx::Connector.

Best,

David
--Apple-Mail=_A609F58D-B2EF-4122-A8C9-A284602BEAC3
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
charset=us-ascii

-webkit-nbsp-mode: space; -webkit-line-break: after-white-space; =
">

On Aug 2, 2011, at 6:30 AM, Feng He wrote:

class=3D"Apple-interchange-newline">
class=3D"Apple-style-span" style=3D"border-collapse: separate; =
font-family: Helvetica; font-style: normal; font-variant: normal; =
font-weight: normal; letter-spacing: normal; line-height: normal; =
orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: =
none; white-space: normal; widows: 2; word-spacing: 0px; =
-webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: =
0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: =
auto; -webkit-text-stroke-width: 0px; font-size: medium; "> class=3D"Apple-style-span" style=3D"font-family: monospace; ">I just =
want to develop a modperl application.
It's a handler, the database =
is Mysql.
Shall I use Apache::DBI, or DBI is just fine =
?

I recommend =
DBIx::Connector.

Best,

D=
avid
=

--Apple-Mail=_A609F58D-B2EF-4122-A8C9-A284602BEAC3--

Re: Apache::DBI

am 03.08.2011 08:49:06 von Feng He

Hi,

Thank you all for the info.

I have finished writting the handler this morning, and have enabled
Apache::DBI in httpd.conf.
My handler is for this url:
http://bizstatus.game.yy.com/upload/

It accept client's uploaded data and write the data to database.
The strange stuff is, when I run more than one process for test, the
items number in database in not correct.

for example:

ab -n 100 -c 1 http://bizstatus.game.yy.com/upload/?arguments

This insert 100 items into database, the select result is correct.

But this one:

ab -n 100 -c 2 http://bizstatus.game.yy.com/upload/?arguments

or:

ab -n 100 -c 3 http://bizstatus.game.yy.com/upload/?arguments


When the client number is larger than one, the items number in
database is not correct.
it's always larger than 100, for example, 101, 102, 103 etc.

So, what's wrong with my program?

The handler looks as:

package ABC;
use strict;
use Apache2::RequestIO ();
use Apache2::RequestRec ();
use Apache2::Connection ();
use Apache2::RequestUtil ();
use Apache2::Request ();
use DBI;


use Apache2::Const -compile => qw(OK NOT_FOUND);

sub handler {

my $r = shift;
my $q = Apache2::Request->new($r);
my $ip = $r->connection->remote_ip;

my $v1 = $q->param('arg1');
my $v2 = $q->param('arg2');


my $db = 'mydb';
my $host = '127.0.0.1';
my $port = 3306;
my $user = '***';
my $passwd = '***';
my $dbh = DBI->connect("dbi:mysql:database=$db;host=$host;port=$port",
$user, $passwd)
or die $DBI::errstr;

my $str = "insert into mytable (v1,v2,check_time)
values(?,?,now())";

my $sth = $dbh->prepare($str);
$sth->execute($v1,$v2) or die $dbh->errstr;
$sth->finish;

$r->content_type('text/plain');
$r->print('OK');

return Apache2::Const::OK;
}

1;



Thank you!

Re: Apache::DBI

am 03.08.2011 14:56:27 von Adam Prime

On 8/3/2011 2:49 AM, Feng He wrote:
> Hi,
>
> Thank you all for the info.
>
> I have finished writting the handler this morning, and have enabled
> Apache::DBI in httpd.conf.
> My handler is for this url:
> http://bizstatus.game.yy.com/upload/
>
> It accept client's uploaded data and write the data to database.
> The strange stuff is, when I run more than one process for test, the
> items number in database in not correct.
>
> for example:
>
> ab -n 100 -c 1 http://bizstatus.game.yy.com/upload/?arguments
>
> This insert 100 items into database, the select result is correct.
>
> But this one:
>
> ab -n 100 -c 2 http://bizstatus.game.yy.com/upload/?arguments
>
> or:
>
> ab -n 100 -c 3 http://bizstatus.game.yy.com/upload/?arguments
>
>
> When the client number is larger than one, the items number in
> database is not correct.
> it's always larger than 100, for example, 101, 102, 103 etc.
>
> So, what's wrong with my program?
>
> Thank you!

The first thing i'd suggest is looking at the access and error logs, and
seeing if there are anything in there that will tell you what's wrong
with it.

Nothing looks wrong at first glance to me, though you should check for
errors on the prepare call.

Adam

Re: Apache::DBI

am 03.08.2011 15:47:16 von Perrin Harkins

On Wed, Aug 3, 2011 at 2:49 AM, Feng He wrote:
> ab -n 100 -c 3 http://bizstatus.game.yy.com/upload/?arguments
>
>
> When the client number is larger than one, the items number in
> database is not correct.
> it's always larger than 100, for example, 101, 102, 103 etc.
>
> So, what's wrong with my program?

I think your program is fine. I suspect ab is not that precise.

- Perrin

Re: Apache::DBI

am 03.08.2011 19:47:23 von Jerry Pereira

--000e0cd328f4e7483b04a99d74ec
Content-Type: text/plain; charset=ISO-8859-1

How about DBIx::Connector?

On Tue, Aug 2, 2011 at 6:30 AM, Feng He wrote:

> Hi,
>
> I just want to develop a modperl application.
> It's a handler, the database is Mysql.
> Shall I use Apache::DBI, or DBI is just fine ?
>
> Thank u.
> Regards.
>



--
Your clothes may be the latest in style but you aint completely dressed
until you wear a smile!
Keep smiling : )

--000e0cd328f4e7483b04a99d74ec
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

How about DBIx::Connector?

On Tue, Aug 2,=
2011 at 6:30 AM, Feng He < gmail.com">shorttag@gmail.com> wrote:
"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding=
-left:1ex;">
Hi,



I just want to develop a modperl application.

It's a handler, the database is Mysql.

Shall I use Apache::DBI, or DBI is just fine ?



Thank u.

Regards.




--
Your clothes may be the=
latest in style but you aint completely dressed until you wear a smile! >Keep smiling : )


--000e0cd328f4e7483b04a99d74ec--