Dear monks,
I am attempting to create a multi-threaded script, which will perform operations on mysql_database. Unfortunately I am having a problem with sharing the mysql connection object. I found DBIx::Threaded modules, which supposedly does exactly what I need (establish pool of connections, and with each database operation draw from the pool), but I can't get it working, more precisely, if I use it as I would use regular DBI module, I get error 'Can't call method "dbix_threaded_start" without a package or object reference', after the prepare line. Is there any special wayt to return the statement handle object.
#!/usr/bin/perl use Net::DNS; use DBI; use 5.10.0; use threads; use threads::shared; use Date::Calc qw(Delta_Days); use Net::DNS::Sendmail; use DBIx::Threaded; #use diagnostics; $| = 1; my $thread_no = shift; my $host = "localhost"; my $database = "test"; my $user = "root"; my $password = ""; my (@date) = (localtime)[5,4,3]; $date[1]++; $date[0] += 1900; my $dbh_t = DBIx::Threaded->connect("DBI:mysql:database=$database;host +=$host", $user, $password); DBIx::Threaded->dbix_threaded_create_pool(10); my $dbh = DBI->connect("DBI:mysql:database=$database;host=$host", $use +r, $password); my $sth = $dbh->prepare("SELECT id,domain,DATE(created) FROM domain_li +st"); $sth->execute(); my $counter = 0; while (my @row = $sth->fetchrow_array()) { my $id = $row[0]; my $domain = $row[1]; my $created = $row[2]; next unless $row[0..3]; my $thr = threads->create(mx_lookup,$id,$domain,$created) unless $ +counter >= $thread_no; $thr->detach && $counter++ if $thr; } $dbh_t->close_all(); $dbh->disconnect(); sub mx_lookup { my $id = shift; my $domain = shift; my $date_c = shift; my @date_c = split /-/, $date_c; my $delta = Delta_Days(@date_c,@date); if ($delta <= 30) { my $sth = $dbh_t->dbix_threaded_start_prepare("select max(id),domain_i +d,changed_from,changed_to,date from mx_history where domain_id=$id"); #this is where the script fails $sth->dbix_threaded_start(); my @row = $sth->fetchrow_array(); my $last_mx = $row[3]; $sth->finish(); } }
(I cut down the code, so only the relevant pieces are included... Thanks for any help clone4

In reply to Threads and multiple DBI connections by clone4

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.