Re: Using DBI

[prev] [thread] [next] [Date index for 2004/12/28]

From: Octavian Rasnita
Subject: Re: Using DBI
Date: 21:56 on 28 Dec 2004
From: "Malcolm J Harwood" <mjhlist-modperl@xxxxxxxxxxx.xxx>

> [Tue Dec 28 21:07:34 2004] [error] DBD::mysql::db prepare failed: handle 2
> is owned by thread 265c564 not current thread 14ce78c (handles can't be
> shared between threads and your driver may need a CLONE method added) at
> f:/web/presa/modules/GetCategories.pm line 18.\n

This means you've got a db handle before the thread was cloned (created by
the
connect_on_init - which connects when the process, not the thread, is
created). The handle can't be shared between the parent and child thread,
generating the above error.

> So I have commented out the following line in preload.pl:
> ###Apache::DBI->connect_on_init("DBI:mysql:database=presa;host=localhost",
> "ODBC", undef, {PrintError =>1, RaiseError=>0, AutoCommit => 1});
>
> And in GetCategories.pm I have used only:
>
> use DBI;
> my $dbh = ...;
>
> Well, in this case the script works, but I don't know if this way of using
> DBI is the best way.

If you are using multiple threads, then yes. (Though I'm not sure how
Apache::DBI's thread pool works with multiple threads, presumably it
provides
seperate pools for each thread, but I could be wrong there).

--

Ok, but I have seen an example in a tutorial where the database is accessed
with the username, and the password from a startup.pl file exactly like
this:

Apache::DBI->connect_on_init("DBI:mysql:database=presa;host=localhost",
"ODBC", undef, {PrintError =>1, RaiseError=>0, AutoCommit => 1});

In what situation can I access the database at the server startup?

I would like to preload the DBI module at the  server startup and to be able
to create persistent connections in order to make them faster.

Thank you.

Teddy


        -- 
        Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html

Using DBI
Octavian Rasnita 19:21 on 28 Dec 2004

Re: Using DBI
Stas Bekman 20:51 on 28 Dec 2004

Re: Using DBI
Malcolm J Harwood 21:18 on 28 Dec 2004

Re: Using DBI
Octavian Rasnita 21:56 on 28 Dec 2004

Re: Using DBI
Malcolm J Harwood 22:09 on 28 Dec 2004

Re: Using DBI
Stas Bekman 22:14 on 28 Dec 2004

Re: Using DBI
Randy Kobes 23:15 on 28 Dec 2004

Re: Using DBI
Randy Kobes 23:27 on 28 Dec 2004

Re: Using DBI
Octavian Rasnita 07:46 on 29 Dec 2004

Re: Using DBI
Randy Kobes 16:24 on 29 Dec 2004

Generated at 12:15 on 16 Jan 2005 by mariachi v0.52