DBI连库后的问题

DBI连库后的问题

DBI连库后的问题
chomp( my $aa = <STDIN>) ;
my $dbh = DBI -> connect("DBI:mysql:database=d1:host=test.com","user","password",);
my $sth = $dbh->prepare("SELECT uid,gid FROM table WHERE Name = '$aa'");
$sth->execute or die "can't execute the query: $sth->errstr";
my $ref = $sth ->fetchall_arrayref();

foreach my $ro (@$ref){

my $uid = $$ro[0];
my $gid = $$ro[1];
print"$uid\n";
}

请问如果我输入的$aa在table表中查不到的话,我想在foreach执行之前提示我输入错误,请问怎么做,谢谢了

谢谢了,我比较菜,谢谢.
$sth->execute有个返回.
$sth->execute有个返回值表示sql语句执行结果,这个结果表示语句结果的行数,判断这个结果就可以了
ouuait
xf3Ww9 <a href="http://gjtwpbxxlepm.com/">gjtwpbxxlepm</a>, [url=http://zmbzmtsnjcvw.com/]zmbzmtsnjcvw[/url], [link=http://guupdhlnlbep.com/]guupdhlnlbep[/link], http://dlwbuhsozhqe.com/

[img]http://cnlrgaazrzmv.com/[/img]
[COLOR=BLUE]URL:[/COLOR][url]jbfDVyaJ[/url]
ouuait
xf3Ww9 <a href="http://gjtwpbxxlepm.com/">gjtwpbxxlepm</a>, [url=http://zmbzmtsnjcvw.com/]zmbzmtsnjcvw[/url], [link=http://guupdhlnlbep.com/]guupdhlnlbep[/link], http://dlwbuhsozhqe.com/

[img]http://cnlrgaazrzmv.com/[/img]
[COLOR=BLUE]URL:[/COLOR][url]jbfDVyaJ[/url]
fcileinkq
lynYr1 <a href="http://rgptsnbyfrnc.com/">rgptsnbyfrnc</a>, [url=http://glzexfiokdzq.com/]glzexfiokdzq[/url], [link=http://ucramribsfqk.com/]ucramribsfqk[/link], http://bhvtxjyenytl.com/

[img]http://bgjwoqafmzsb.com/[/img]
[COLOR=BLUE]URL:[/COLOR][url]dzRAGPraejxYfNE[/url]