php pdo显示错误准备执行

时间:2014-09-24 12:27:49

标签: php mysql pdo

如何使用PDO显示错误并执行此特定准备并执行:

try 
{

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

    $stmt = $pdo->prepare("SELECT ZZZZZZ, nomepostazimiele FROM postazimiele");
    $stmt->execute();

    while ($row_postazimiele = $stmt->fetch(PDO::FETCH_ASSOC)) 
    {
        $idnomepostazi = $row_postazimiele['idpostazi'];
        $nomepostazimiele = $row_postazimiele['nomepostazimiele'];

        echo "<option value=\"$nomepostazimiele\">$nomepostazimiele</option>";
    }
} 
catch (pdoException $e) 
{
    echo 'Attenzione: ' . $e->getMessage();
    $output = "Impossibile collegarsi al Data Base, Utente o Password errati"
            . "<br>" . "<br>" . "prego riprovare" . $e 
            . "<br>" . "<br>" . "<a href='miele.php'>Clicca QUI per ritornare alla pagina principale</a>";

    include 'errore.html.php';
    exit();
}

如果我在SELECT中出错,则不会出现错误。为什么呢?

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:-1)

您需要获取执行的输出,您希望显示错误而不是异常。

if($stmt->execute()){
    echo "Error: ".$stmt->errorInfo();
}