note 99518 added to class.pdoexception
| From: | Marco01_809" | Date: | Sat, 21 Aug 2010 12:06:18 +0000 |
| Subject: | note 99518 added to class.pdoexception | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-171911@lists.php.net to get a copy of this message | ||
This is a PDOException Error handler for Using/Debugging in Web Browser.
<?php
echo '<html><head><title>PHP PDO
Tests</title></head><body>';
// Try the following code:
try {
$db = new PDO('sqlite:database.sdb'); // Create a new PDO Object
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Set Errorhandling to
Exception
$db->query("BlaBlaBla"); // Query something wrong
$db = null; // "Disconnect"
}
catch (PDOException $err) {
// Catch Expcetions from the above code for our Exception Handling
$trace = '<table border="0">';
foreach ($err->getTrace() as $a => $b) {
foreach ($b as $c => $d) {
if ($c == 'args') {
foreach ($d as $e => $f) {
$trace .= '<tr><td><b>' . strval($a) .
'#</b></td><td align="right"><u>args:</u></td>
<td><u>' . $e . '</u>:</td><td><i>' . $f .
'</i></td></tr>';
}
} else {
$trace .= '<tr><td><b>' . strval($a) .
'#</b></td><td align="right"><u>' . $c .
'</u>:</td><td></td><td><i>' . $d .
'</i></td>';
}
}
}
$trace .= '</table>';
echo '<br /><br /><br /><font
face="Verdana"><center><fieldset style="width: 66%; border: 4px solid
white; background: black;"><legend><b>[</b>PHP PDO Error ' .
strval($err->getCode()) . '<b>]</b></legend> <table
border="0"><tr><td
align="right"><b><u>Message:</u></b></td><td><i>'
. $err->getMessage() . '</i></td></tr><tr><td
align="right"><b><u>Code:</u></b></td><td><i>'
. strval($err->getCode()) . '</i></td></tr><tr><td
align="right"><b><u>File:</u></b></td><td><i>'
. $err->getFile() . '</i></td></tr><tr><td
align="right"><b><u>Line:</u></b></td><td><i>'
. strval($err->getLine()) . '</i></td></tr><tr><td
align="right"><b><u>Trace:</u></b></td><td><br
/><br />' . $trace .
'</td></tr></table></fieldset></center></font>';
}
echo '</body></html>';
?>
----
Server IP: 85.214.154.209
Probable Submitter: 91.39.254.236
----
Manual Page -- http://www.php.net/manual/en/class.pdoexception.php
Edit -- https://master.php.net/note/edit/99518
Del: integrated -- https://master.php.net/note/delete/99518/integrated
Del: useless -- https://master.php.net/note/delete/99518/useless
Del: bad code -- https://master.php.net/note/delete/99518/bad+code
Del: spam -- https://master.php.net/note/delete/99518/spam
Del: non-english -- https://master.php.net/note/delete/99518/non-english
Del: in docs -- https://master.php.net/note/delete/99518/in+docs
Del: other reasons-- https://master.php.net/note/delete/99518
Reject -- https://master.php.net/note/reject/99518
Search -- https://master.php.net/manage/user-notes.php