You can join tables in different databases if they are on the same server. Also consider using placeholders (?) in the queries. For example
#!/usr/bin/perl use strict; use warnings; use DBI; my $dbh = DBI->connect('dbi:mysql:alicenet','user','password', {mysql_enable_utf8 => 1,RaiseError => 1,PrintError => 1}) or die "Connection Error: $DBI::errstr\n"; my $where = 'WHERE M.failed < 3 AND M.lasttry < (NOW() - INTERVAL 90 MINUTE)'; my $sql = "SELECT COUNT(id) FROM mailcue AS M $where"; #count the messages my ($count) = $dbh->selectrow_array($sql); #max number of cued messages to fetch my $max = ($count < 180)? 30 : int($count/6); $sql = "SELECT U.email,M.subject,M.message,M.id,M.failed FROM mailcue as M LEFT JOIN anetauth.userauth as U ON U.id = M.userid $where ORDER BY M.id LIMIT ?"; my $sql_fail = "UPDATE mailcue SET lasttry = NOW(),failed = ? WHERE id = ?"; my $sth_fail = $dbh->prepare($sql_fail); my $sql_ok = 'DELETE FROM mailcue WHERE id = ?'; my $sth_ok = $dbh->prepare($sql_ok); my $ar = $dbh->selectall_arrayref($sql,undef,$max); for (@$ar){ my ($email_addr,$subject,$message,$id,$failed) = @$_; # replace print with email create and send print " -------------------- to = $email_addr subject = $subject body = $message id = $id failed = $failed =================="; my $response = 'fail'; # test if ($response eq ''){ # change to suit $sth_ok->execute($id); } else { $sth_fail->execute($failed+1,$id); } }
poj

In reply to Re^3: Use of uninitialized value in lc by poj
in thread Use of uninitialized value in lc by Alice Wonder

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.