PHP Doku:: Fehler und Fehlerbehandlung - pdo.error-handling.html

Verlauf / Chronik / History: (3) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDatenbankerweiterungenAbstraktionsebenenPHP Data ObjectsFehler und Fehlerbehandlung

Ein Service von Reinhard Neidl - Webprogrammierung.

PHP Data Objects

<<Prepared Statements und Stored Procedures

Large Objects (LOBs)>>

Fehler und Fehlerbehandlung

PDO bietet Ihnen die Wahl unter 3 verschiedenen Strategien zur Fehlerbehandlung, um Ihrem Stil der Anwendungsentwicklung gerecht zu werden.

PDO benutzt Fehler-Codes nach SQL-92 SQLSTATE. Individuelle PDO-Treiber sind selbst verantwortlich, ihre nativen Fehler-Codes in die entsprechenden SQLSTATE-Pendants umzuwandeln. Die Methode PDO::errorCode() gibt einen einzelnen SQLSTATE-Code zurück. Wenn Sie genauere Informationen über einen Fehler benötigen, bietet PDO auch die Methode PDO::errorInfo(), die ein Array zurückgibt, das den SQLSTATE-Code, den treiberspezifischen Fehler-Code und die treiberspezifische Fehlermeldung enthält.


2 BenutzerBeiträge:
- Beiträge aktualisieren...
john dot navratil at sbcglobal dot net
8.06.2008 0:38
SQLSTATE code strings cannot be counted on, yet.  Attempting to insert a row with a duplicate key provides the 23000 code (constraint violation) when using mysql, but HY000 when using Oracle.  The PDO docs say this is the responsibility of the driver to convert.  In the meantime, the app will have to do it.
radical
22.04.2008 21:45
For your convenience, here's an example of how to set the error handling:

<?php

  $dbh
= new PDO( /* your connection string */ );
 
$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
 
// . . .
?>



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)