谢谢,雪悟,二球.
Pear DB 新手入门指南5
上一篇 /
下一篇 2006-12-18 17:57:28
/ 个人分类:全是帅的不能再输啦
"EI)@3y/Z(?6DC1GS7T*_%K0高级示例:
SfDA ~9_w\0
<?phpPHPChina 开源社区门户"d srxx
// Define the app environment (this is: what errors you want to output) 6o{
@:ACQ ZUO0define ('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()); \ PPX I*_&?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_&CoD#O#w0T0require_once 'DB.php';PHPChina 开源社区门户!eAz#r5q;XJ
// On error, call the "handle_pear_error" function back p{t+tgz @0// You can also use an object as pear error handler so: Uo1{{4E0j0// setErrorHandling(PEAR_ERROR_CALLBACK, array($object,'method_name'); d4t6l
JTD6N],O;Y0PEAR::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`[O0while ($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-lf]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}0set_error_handler ('php_error_handler');PHPChina 开源社区门户enDx?
// 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_string, E_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&iOR,mR%{-I
$db = DB::connect('pgsql://postgres@localhost/no_db'); pXh\4U8L"P0... qWeAT0?>
|
g-n.UV(R z};de0<完>PHPChina 开源社区门户Xxd#R*GX
相关阅读:
- 用JS实现..无刷新选择分类. (帅的不能再输啦, 2006-12-04)
- 榨干 PHP,不得不转的一篇PHP使用技巧! (帅的不能再输啦, 2006-12-05)
- 写给桃子,也写给自己... (帅的不能再输啦, 2006-12-06)
- 使用指南 (帅的不能再输啦, 2006-12-14)
- 灿烂人生,谢谢二球. (帅的不能再输啦, 2006-12-14)
- 工作和态度,与时间管理的艺术!!!(推荐阅读) (帅的不能再输啦, 2006-12-16)
- Pear DB 新手入门指南(转) (帅的不能再输啦, 2006-12-18)
- Pear DB 新手入门指南2 (帅的不能再输啦, 2006-12-18)
- Pear DB 新手入门指南3 (帅的不能再输啦, 2006-12-18)
- Pear DB 新手入门指南4 (帅的不能再输啦, 2006-12-18)
导入论坛
收藏
分享给好友
管理
举报
TAG:
全是帅的不能再输啦