Error: handles can't be shared between threads

[prev] [thread] [next] [Date index for 2005/05/19]

From: Octavian Rasnita
Subject: Error: handles can't be shared between threads
Date: 17:47 on 19 May 2005
Hi,

I am using mod_perl 2.0.0 under Windows 2000, with perl 5.8.6, Apache
2.0.54, and Apache::DBI  version 0.96.

I want to create a module that uses DBI.pm for connecting to the MySQL
database, then using that module in all other modules that might need a
connection.

Here is the module I have tried:

package Site::MySQL;

use strict;
use DBI ();

sub dbh {
return DBI->connect("DBI:mysql:database=test;host=localhost", "root", undef,
{RaiseError => 0, PrintError => 1, AutoCommit => 1});
}
1;

I get the $dbh in other modules using:
my $dbh = Site::MySQL::dbh();

If I run the programs in command line, they work fine, but if I run them
using mod_perl, it gives an error in the log file:

[Thu May 19 20:36:01 2005] [error] DBD::mysql::db prepare failed: handle 2
is owned by thread 225321c not current thread 17cde94 (handles can't be
shared between threads and your driver may need a CLONE method added) at
e:/web/presa3/modules/Presa/Categories.pm line 34.\n

I have tried to use and not to use Apache::DBI but with the same results.

I don't have any idea where could be the problem. Is the module that uses
DBI bad? Isn't a good idea to create a functional module instead of an OOP
one?
Or... what can I try to make them work?

Thank you.

Teddy


Error: handles can't be shared between threads
Octavian Rasnita 17:47 on 19 May 2005

Re: Error: handles can't be shared between threads
Perrin Harkins 20:48 on 19 May 2005

Re: Error: handles can't be shared between threads
Octavian Rasnita 01:32 on 20 May 2005

Re: Error: handles can't be shared between threads
Perrin Harkins 03:50 on 20 May 2005

Re: Error: handles can't be shared between threads
Octavian Rasnita 20:27 on 20 May 2005

Re: Error: handles can't be shared between threads
Perrin Harkins 20:45 on 20 May 2005

Generated at 15:53 on 25 May 2005 by mariachi v0.52