谢谢,雪悟,二球.

Pear DB 新手入门指南5

上一篇 / 下一篇  2006-12-18 17:57:28 / 个人分类:全是帅的不能再输啦

"EI)@3y/Z(?6DC1G S7T*_%K0高级示例:

SfDA ~9_w\0
 
<?phpPHPChina 开源社区门户"d srxx
// Define the app environment (this is: what errors you want to output)
6o{ @:ACQ ZUO0
define ('DEBUG_ENV'true);PHPChina 开源社区门户M8z^o1M5f @!ZV-Bs
// This function will handle all errorsPHPChina 开源社区门户:yk R;q+xg
function handle_pear_error ($error_obj) {PHPChina 开源社区门户O*a;AO s i^,Tx5`7Y
    
// Be verbose while developing the applicationPHPChina 开源社区门户HJO+_9^4]@,X
    
if (DEBUG_ENV) {
U7h5WAP3Vp1^Z"[0        die (
$error_obj->getMessage()."\n".$error_obj->getDebugInfo());
\ PPXI*_&?0    
// Dump a silly message if the site is in production
Z?Y-R.C7N0    
} else {
}DEQ"i~I0        die (
'Sorry you request can not be processed now. Try again later');
J,d5j,B&{0    }
6V_ H0k] S0}
y~I9j { J0
A0_&Co D#O#w0T0require_once 
'DB.php';PHPChina 开源社区门户!eAz#r5q;X J
// On error, call the "handle_pear_error" function back
p{t+t gz@0// You can also use an object as pear error handler so:
Uo1{{4E0j0// setErrorHandling(PEAR_ERROR_CALLBACK, array($object,'method_name');
d4t6l J TD6N ],O;Y0
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK'handle_pear_error');
s;u'~[@U0
$db DB::connect('pgsql://postgres@localhost/site_db');
2z)o8k-{aI,y%T0
$res $db->query('select id from no_table');
R0x j {MyT!@%w@J,c0
// at this point the execution is aborted and the "handle_pear_error"PHPChina 开源社区门户4Jnwaq,Yd'L-y
// function is called with the error object as its first argument
a8\ {x4` [O0
while ($row $res->fetchRow()) {PHPChina 开源社区门户!EL.KW5qZ r? n
    ...PHPChina 开源社区门户0[!|aNn|
}
3ZfQ3\og5W3v0...
k-X6_x;B#C"DJ0
?>
 

;n;F(K)~d(It0下面为扩展错误机制提供了一个很好的想法:PHPChina 开源社区门户"Kf$G'm~ o5r

 
<?php
*?RhT SRL"FY.p }0error_reporting 
(E_ALL E_NOTICE);PHPChina 开源社区门户P-l f ]4G*\.D G
// this function will handle all errors reported by PHPPHPChina 开源社区门户w,i!Z"l ~#V%j
function php_error_handler ($errno$errstr$errfile$errline) {PHPChina 开源社区门户X&k f0`{(px
    die (
"In $errfile, line: $errline\n<br>$errstr");
n&ec!p3v}.ec6?0}
+Bk*F&a XQ2JJG}0
set_error_handler ('php_error_handler');PHPChina 开源社区门户e nDx?
// this function will catch errors generated by Pear,PHPChina 开源社区门户_ `~ W8kg
// transform it to PHP errors and trigger them to the php_error_handlerPHPChina 开源社区门户+`{&~|B8@o
function pear_error_handler ($err_obj) {PHPChina 开源社区门户/f)L}:FH7Y#^j
    
$error_string $err_obj->getMessage() . '<br>' $error_obj->getDebugInfo();
~%Go({KJ1e2b,q0    
trigger_error ($error_stringE_USER_ERROR);
R1`PnrM0}PHPChina 开源社区门户!TX}P ^T
require 
'DB.php';PHPChina 开源社区门户:f8LhC+]&o d
PEAR::setErrorHandling (PEAR_ERROR_CALLBACK'pear_error_handler');PHPChina 开源社区门户;`mRl3`D
// force an errorPHPChina 开源社区门户Z4`KL&i OR,mR%{-I
$db DB::connect('pgsql://postgres@localhost/no_db');
pXh\4U8L"P0...
qWeAT0
?>
 

 

g-n.UV(R z};de0

<>PHPChina 开源社区门户 X xd#R*GX


TAG: 全是帅的不能再输啦

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

Open Toolbar