0

如果 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 ......但是这段代码将始终执行

4

0 回答 0