in reply to selecting again from a mysql database

Ok, maybe I'm a moron 'cause I'm not seeing it, but *what* are these things - `Stat`, `Project`, and `Version`??? If Stat, Project, and Version are column names, then you *don't* need to quote them, especially with backticks, which have special meaning in Perl.

And, as hardburn already said, and others including myself have suggested to you before in previous nodes, USE PLACEHOLDERS. Is there a reason that you are intentionally not using placeholders?

In this code:
while (my ($identifier)=$sth->fetchrow_array ) {
fetchrow_array returns an *array* - not an array reference. So, $identifier in that line should be @identifier. Or, change fetchrow_array to fetchrow_arrayref.

Another problem which others have already pointed out - when you do 'select *', you have no idea what order the columns are being fetched in. If you explicitely named the columns in the select, then you know what order they are fetched in so you can order the fields receiving the fetch, like this:
my $sth=$dbh->prepare(qq{ SELECT name, state, phone FROM user }); $sth->execute(); while (my ($name, $state, $phone)=$sth->fetchrow_array ) { ### now you can use $name, $state, and $phone ### print "User name: $name\n"; print " state: $state\n"; print " phone: $phone\n"; } $sth->finish;
HTH.

Replies are listed 'Best First'.
Re: Re: selecting again from a mysql database
by graff (Chancellor) on Nov 26, 2003 at 01:11 UTC
    Yes, `Stat`, `Project` and `Version` are being used as column names in the SQL query. No, the back-ticks do not have special meaning for Perl in this case, because the query text (with the back-ticks) is enclosed in double-quotes.

    Back-ticks in an SQL statement are sometimes needed around a column name if that name also happens to be a reserved keyword in SQL.

    I just learned this myself recently, when I tried to inspect a table that a co-worker had created, with a column called "group" -- which is a natural enough name for a column, but you can't do a query like "select group from my_table" unless you put back-ticks around that column name, because "group" is a reserved word (as in "group by").

Re: Re: selecting again from a mysql database
by iburrell (Chaplain) on Nov 25, 2003 at 19:40 UTC
    fetchrow_array returns an array and it is assigning into an array. This is a pretty standard idiom for reading single columns. The while loop even distinguishes between an empty array for end of the data set and undef for NULL value.
    my ($identifier)=$sth->fetchrow_array(); my @array = $sth->fetchrow_array(); ($identifier) = @array;