$cth->prepare("SELECT COUNT(*) From Table1 Where....."); $cth->execute($Server1,$App1,$Inst1,); if (@rows == "0") { $sth->prepare("SELECT 1"); $sth->execute($Svr1,$ap1,$in); } else { $sth->prepare("SELECT 2") $sth->execute($svr1,$ap); }