Re: Using DBI

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

From: Malcolm J Harwood
Subject: Re: Using DBI
Date: 21:18 on 28 Dec 2004
On Tuesday 28 December 2004 02:21 pm, Octavian Rasnita wrote:

> I am a new member on this list and after reading the posts from this list
> in the last few days, I don't even know if this is the apropriate place for
> asking questions about using mod_perl.

It is. :)

> in preload.pl:
> use Apache::DBI();
> use DBI ();
> DBI->install_driver("mysql");
> ###Apache::DBI->connect_on_init("DBI:mysql:database=presa;host=localhost",
> "ODBC", undef, {PrintError =>1, RaiseError=>0, AutoCommit => 1});

I assume from the later comment that the above was not supposed to be 
commented out in the first example.

> [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).



        -- 
        "We are grey. We stand between the candle and the stars"
- Babylon 5

-- 
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