1.PDO::ERRMODE_SILENT 靜默模式,不終止代碼,只能使用 $pdo->errorCode() 和 $pdo->errorInfo() 獲取錯誤資訊 , 這個是默認情況下 , 也就是不停斷 , 不記日志
注意這種形式下不容易錯誤排查
2.PDO::ERRMODE_WARNING 警告模式,不終止代碼,在錯誤日志中出現warning型別的錯誤資訊
/var/log/apache/xxx-error.log
[Fri Mar 09 16:02:50 2018] [error] [client 61.135.152.130] PHP Warning: PDOStatement::execute(): SQLSTATE[42S02]: Base table or view not found: 1146 Table 'sinanet.mass_list' doesn't exist in /mnt/publi
3.PDO::ERRMODE_EXCEPTION 例外模式,終止代碼,拋出例外資訊,使用try()catch(){}捕獲
記錄到應用日志里/var/log/sinamail/webmail.log
Mar 9 15:54:13 vm-228-187 webmail: 2018-03-09 15:54:13 xxx xxxx 61.135.152.130 /usr/local/wa.php - APP_RUN_ACTION msg=>SQLSTATE[42S02]: Base table or view not found: 1146 Table 'sinanet.mass_list' doesn't exist,code=>42
例外模式另一個非常有用的是,相比傳統 PHP 風格的警告,可以更清晰地構建自己的錯誤處理,而且比起靜默模式和顯式地檢查每種資料庫呼叫的回傳值,例外模式需要的代碼/嵌套更少,
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/65105.html
標籤:PHP
上一篇:【SpringCloud】02.微服務與SpringCloud
下一篇:微擎框架的快取機制實作原始碼解讀
