我想知道如何打印以下Perl代码段中的结果:
$sth = $dbh->prepare("SELECT * FROM table_name");
$sth->execute();
如果您输入“SELECT * FROM table_name; into mySQL并显示整个关系,我想看看您会看到什么。是否有来自$ sth的返回值可以循环并打印出来?” / p>
答案 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 />";
}