Perl DBI MySQL更新

时间:2012-10-11 04:42:01

标签: mysql perl dbi

我想知道如何打印以下Perl代码段中的结果:

    $sth = $dbh->prepare("SELECT * FROM table_name");
    $sth->execute();

如果您输入“SELECT * FROM table_name; into mySQL并显示整个关系,我想看看您会看到什么。是否有来自$ sth的返回值可以循环并打印出来?” / p>

1 个答案:

答案 0 :(得分:2)

# BIND TABLE COLUMNS TO VARIABLES
$sth->bind_columns(undef, \$id, \$product, \$quantity);

# LOOP THROUGH RESULTS
while($sth->fetch()) {
   print "$id, $product, $quantity <br />";
}