in reply to Re^2: basic dbi question
in thread basic dbi question

i was wondering if i could make the statement shorter

I presume you mean the code snippet rather than some specific but unspecified statement. If so, you already did. ->execute($val1, $val2) became ->execute().

What else do you want? You obviously can't skip preparing and executing the statement, and you can't skip fetching the result. That really doesn't leave anything to remove. You could combine prepare and execute, though.

my $sth = prepare_and execute($dbh, " SELECT cols FROM ".$dbh->quote_identifier($tableName)." WHERE col=constant AND col2=constant "); while (my $row = $sth->fetchrow_hashref) { ... }

Up to you to write prepare_and execute, but it's trivial.

DBI has shortcuts for collecting your data, but you didn't show how you use the data you fetch.