Re: Using DBI
[prev]
[thread]
[next]
[Date index for 2004/12/28]
Octavian Rasnita wrote:
> Hi all,
>
> 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.
> If it is not, please tell me if there is another list which could be more
> useful for a mod_perl beginner.
>
> I want to use the DBI module with mod_perl 2 with Perl 5.8.4, and for the
> moment... under Windows 2000.
>
> I have tried:
>
> In httpd.conf:
> PerlRequire [path]/preload.pl
>
> 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});
>
> in the GetCategories.pm module:
> ##use Apache::DBI;
> use DBI;
> my $dbh = ...;
>
> I have tried more combinations, but every time I get the following error in
> the logs:
>
> [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
> -----
>
> 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.
I'm afraid your script, just appears to be working and if you put it under
a stress testing, that will really involve multithreading you will see
the same problem. Take a look at:
http://search.cpan.org/~rudy/DBD-mysql-2.9004/lib/DBD/mysql.pm#MULTITHREADING
-----------------------------
The multithreading capabilities of DBD::mysql depend completely on the
underlying C libraries: The modules are working with handle data only, no
global variables are accessed or (to the best of my knowledge) thread
unsafe functions are called. Thus DBD::mysql is believed to be completely
thread safe, if the C libraries are thread safe and you don't share
handles among threads.
The obvious question is: Are the C libraries thread safe? In the case of
MySQL the answer is "mostly" and, in theory, you should be able to get a
"yes", if the C library is compiled for being thread safe (By default it
isn't.) by passing the option -with-thread-safe-client to configure. See
the section on How to make a threadsafe client in the manual.
-----------------------------
--
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@xxxxxx.xxx http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
--
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
|