in reply to Can insert but not select

It is possible with some databases to have permission to INSERT and UPDATE but not SELECT.

It would help us diagnose the problem if you'd show some code that's giving you the problem.

Replies are listed 'Best First'.
Re^2: Can insert but not select
by zoophagous (Novice) on Jan 03, 2009 at 05:37 UTC
    Thanks! Here is the code in question.
    $rowCheckQuery = qq{SELECT color_id FROM color WHERE color=?}; foreach my $color (@color){ # trim whitespace $color =~ s/^\s+|\s+$//gm; # print "Color is - ", $color, " -\n\n"; my $sth = $dbh->prepare($rowCheckQuery); $sth->execute($color); while(my $color_test = $sth->fetchrow_arrayref) +{ push @color_test, $color_test; } }
    Also I double checked the user I am using for the script and it has global select permissions. I can select on other tables in the same db.... just very oddly not two of my tables. This might be more of a mysql issue. I'm not sure.

    Thanks again.

      And what behavior do you see from this?

      Note that fetchrow_arrayref always returns the same array reference (see the DBI documentation). That means if you want to store all the rows (as you appear to be attempting), you have to copy the array.

      while(my $color_test = $sth->fetchrow_arrayref) { push @color_test, [ @{$color_test} ]; }
        The behavior I am seeing is the foreach loop hangs.

        The loops executes if I put an insert statement in place of the select. Or will execute if I select from a different table.

        If I put a print statement below the $sth execute it doesn't print and the loop doesn't iterate.

      In addition to comments already made, you also want to prepare your statement outside of the loop. You are effectively negating the performance benefit of running the prepare command.

      --MidLifeXis