newbie question - PERL/MYSQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rook
    New Member
    • Mar 2006
    • 2

    newbie question - PERL/MYSQL

    Hello,

    Hopefully this is the right place to post my question.

    I'm trying to create a dynamic query by populating a select statement from an array. The code below is one fetchrow_array problem away from working. Unfortunately, I'm googled out and can't seem to figure out why the fetchrow_array function within the while statement doesn't run.

    ####
    foreach $match(@match) {
    ($tlast, $tfirst) = split (/:/, $match);

    #Select last, first, and RESP of db users
    $sql = qq{SELECT LAST, FIRST, RESP FROM data };
    $sql .= qq{WHERE LAST="$tlast" AND FIRST="$tfirst" };

    #Prep and execute SQL
    $st_handle = $db_handle->prepare($sql ) || die "Cannot prepare SQL";
    $st_handle->execute || die "Cannot select record" . $st_handle->errstr();

    ($lastDB, $firstDB, $respDB) = $st_handle->fetchrow_arr ay || warn($st_handle );
    }
    #####
    I get the following warning:

    DBI::st=HASH(0x 824e578) when the fetchrow_array executes.

    Anyone have additional resources I could look into?

    Thanks in advance for any help.
    Last edited by rook; Mar 24 '06, 03:01 PM.
  • rook
    New Member
    • Mar 2006
    • 2

    #2
    finally...after much head banging...

    I think the problem was a line return at the end of each line, chomp was the fix for that. Added the '?' to the select, which helped build the dynamic query. Also, the order wasn't very good, the prepare is better placed outside the loop. There's probably a better way but hope this helps someone else...

    ####

    #Select last, first, and RESP of db users
    $sql = qq{SELECT LAST, FIRST, RESP FROM testdata };
    $sql .= qq{WHERE LAST=? AND FIRST=? };

    #Prep and execute SQL
    $st_handle2 = $db_handle2->prepare($sql ) || die "Cannot prepare SQL";

    my (@row);
    foreach $match(@match) {
    ($tlast, $tfirst) = split (/:/, $match);
    chomp ($tlast, $tfirst);
    $st_handle2->execute($tlast , $tfirst) || die "Cannot select record" . $st_handle2->errstr();
    @row = $st_handle2->fetchrow;
    print "$row[0]\t$row[1]\t$row[2]\n";
    }

    Comment

    Working...