Any Perl DBI experts?
    Matt Shields 
    matt-urrlRJtNKRMsHrnhXWJB8w at public.gmane.org
       
    Wed Oct 14 07:52:34 EDT 2009
    
    
  
I'm using DBI to query a MySQL database and I've used the following in
numerous scripts I've written.  In every previous case I knew there was data
in the resultset, but this time there may or may not be data.  If there
isn't data, I get an error with the bind_columns statement.  How can I test
to see there are results before doing the bind_columns and while?
$sql = "SELECT id, name FROM table";
$query = $dbh->prepare(qq{ $sql }) or die "Can't prepare SQL statement:
$dbh::errstr\n";
$query->execute or die "Can't execute SQL statement: $dbh::errstr\n";
$query->bind_columns(\$id,\$name);
while ($query->fetch) {
 print "$id - $name\n";
}
-matt
http://www.sysadminvalley.com
http://www.beantownhost.com
http://www.linkedin.com/in/mattboston
Ted Turner <http://www.brainyquote.com/quotes/authors/t/ted_turner.html>  -
"Sports is like a war without the killing."
    
    
More information about the Discuss
mailing list