v5:userguide:error_handling
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
userguide:error_handling [2015/11/29 22:17] – [Exception Trapping] mnewnham | v5:userguide:error_handling [2018/06/27 16:18] (current) – function names starting with lowercase (#430) dregad | ||
---|---|---|---|
Line 5: | Line 5: | ||
===== PHP set_error_handler ===== | ===== PHP set_error_handler ===== | ||
- | Once the PHP set_error_handler is used to override the default error handling, then the ' | + | Once the PHP set_error_handler is used to override the default error handling, then the ' |
- | --------------------------------------- | + | |
+ | --------------------------------------------------- | ||
<WRAP right box round> | <WRAP right box round> | ||
== See Also == | == See Also == | ||
- | [[reference: | + | [[v5:reference:connection: |
</ | </ | ||
===== adodb-errorhandler.inc.php ===== | ===== adodb-errorhandler.inc.php ===== | ||
Line 26: | Line 28: | ||
$result = $db-> | $result = $db-> | ||
</ | </ | ||
+ | |||
+ | ===== error_reporting ===== | ||
+ | The ADOdb error handler is not dependent on [[http:// | ||
+ | |||
+ | <code php> | ||
+ | function ADODB_Error_Handler($dbms, | ||
+ | { | ||
+ | |||
+ | /* | ||
+ | * Remark out this line to trap errors when error_reporting = 0 | ||
+ | */ | ||
+ | if (error_reporting() == 0) | ||
+ | return; // obey @ protocol | ||
+ | |||
+ | </ | ||
+ | |||
===== Override Error Trap/Resume ===== | ===== Override Error Trap/Resume ===== | ||
Line 49: | Line 67: | ||
set_error_handler(' | set_error_handler(' | ||
- | $db->Execute('DROP INDEX index_that_might_not_exist' | + | $db->execute('DROP INDEX index_that_might_not_exist' |
/* | /* | ||
Line 58: | Line 76: | ||
</ | </ | ||
+ | |||
+ | ===== Using A Class Method ===== | ||
+ | <code php> | ||
+ | class c | ||
+ | { | ||
+ | function e() | ||
+ | { | ||
+ | print "ERROR TRAP"; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | $c = new c; | ||
+ | |||
+ | $db-> | ||
+ | </ | ||
+ | |||
+ | ===== Combining With Custom Error Handling ===== | ||
+ | If you use '' | ||
+ | |||
+ | <code php> | ||
+ | error_reporting(E_ALL); | ||
+ | |||
+ | function myErrorHandler($p1, | ||
+ | { | ||
+ | /* | ||
+ | * Do some non-adodb handling | ||
+ | */ | ||
+ | return true; | ||
+ | } | ||
+ | |||
+ | set_error_handler(' | ||
+ | |||
+ | include ' | ||
+ | include ' | ||
+ | </ | ||
+ | |||
+ | |||
===== Exception Trapping ===== | ===== Exception Trapping ===== | ||
Line 69: | Line 124: | ||
try | try | ||
{ | { | ||
- | $db = NewADOConnection(" | + | $db = newADOConnection(" |
} | } | ||
Line 80: | Line 135: | ||
</ | </ | ||
- | |||
- | ADOdb also provides two custom handlers which you can modify for your needs. The first one is in the **adodb-errorhandler.inc.php** file. This makes use of the standard PHP functions [[http:// | ||
- | |||
- | Including the above file will cause _trigger_error($errorstring, | ||
- | (a) Connect() or PConnect() fails, or | ||
- | (b) a function that executes SQL statements such as Execute() or SelectLimit() has an error. | ||
- | (c) GenID() appears to go into an infinite loop. | ||
- | |||
- | The $errorstring is generated by ADOdb and will contain useful debugging information similar to the error.log data generated below. This file adodb-errorhandler.inc.php should be included before you create any ADOConnection objects. | ||
- | |||
- | If you define error_reporting(0), | ||
- | |||
- | <code php> | ||
- | error_reporting(E_ALL); | ||
- | |||
- | include(' | ||
- | include(' | ||
- | include(' | ||
- | |||
- | $c = NewADOConnection(' | ||
- | $c-> | ||
- | $rs=$c-> | ||
- | if ($rs) | ||
- | rs2html($rs); | ||
- | </ | ||
===== Logging Error Messages ===== | ===== Logging Error Messages ===== | ||
Line 125: | Line 155: | ||
- | $c = NewADOConnection(' | + | $c = newADOConnection(' |
- | $c->PConnect(' | + | $c->pConnect(' |
- | $rs=$c->Execute(' | + | $rs=$c->execute(' |
if ($rs) | if ($rs) | ||
Line 137: | Line 167: | ||
The following message will be logged in the error.log file: | The following message will be logged in the error.log file: | ||
- | 2001-10-28 14:20:38 mysql error: [1146: Table ' | + | 2001-10-28 14:20:38 mysql error: [1146: Table ' |
+ | | ||
===== PEAR_ERROR ===== | ===== PEAR_ERROR ===== | ||
Line 149: | Line 180: | ||
include(' | include(' | ||
- | $c = NewADOConnection(' | + | $c = newADOConnection(' |
- | $c->PConnect(' | + | $c->pConnect(' |
- | $rs=$c->Execute(' | + | $rs=$c->execute(' |
if ($rs) | if ($rs) | ||
Line 177: | Line 208: | ||
===== MetaError and MetaErrMsg ===== | ===== MetaError and MetaErrMsg ===== | ||
- | If you need error messages that work across multiple databases, then use [[reference: | + | If you need error messages that work across multiple databases, then use [[v5:reference:connection: |
===== Error Messages ===== | ===== Error Messages ===== | ||
- | Error messages are outputted using the static method ADOConnnection:: | + | Error messages are outputted using the static method |
+ | |||
+ | | ||
+ | |||
+ | By default, it sends the messages to the standard output. You can override this to perform error logging. |
v5/userguide/error_handling.1448831829.txt.gz · Last modified: 2017/04/21 11:39 (external edit)