如果select查询返回不返回false,则break尝试catch

时间:2013-11-04 20:01:30

标签: php mysql pdo

如果SELECT查询返回false,我希望我的代码执行, 这是我的以下代码:

    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $dbh->beginTransaction();

    if(!$dbh->query($stmt)){
        $query->execute();

        if($stmt->execute()){
            while($row = $stmt->fetch()){
                for ($i = 0;
                    $i < count($defect[0]);
                    $i++){
                    $stmtDefect->bindParam(':purgeID', $row['purgeID']);
                    $stmtDefect->bindParam(':defectID', $defect[0][$i]);
                    $stmtDefect->bindParam(':action', $action[0][$i]);
                    $stmtDefect->execute();
                }//end for
            }//end while
        }//end if

        $dbh->commit();
        echo "Data Successfully added";
    } else {
        echo "Sequence: " . $sequence . " already checked";
    }

我知道如果找不到行,query()将返回false ....但是这段代码将始终执行

0 个答案:

没有答案