开发者

can we have two error modes in pdo

开发者 https://www.devze.com 2023-03-13 14:24 出处:网络
Can i join 开发者_C百科warning as well as error for pdo\'s using set attribute right now i have this line

Can i join 开发者_C百科warning as well as error for pdo's using set attribute

right now i have this line

setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION | PDO::ERRMODE_WARNING );

and i am getting warning

Warning: PDO::setAttribute() [pdo.setattribute]: SQLSTATE[HY000]: General error: invalid error mode in C:\wamp\www\PDO\MyPDO.php on line 18

if i remove the | PDO::ERRMODE_WARNING it works great but i like to c warnings as well. is it allowed in pdo or there is some other way ? .


If you really need to do this, you could write a function that you call whenever you catch PDOException that calls trigger_error(), but you'll need to call it in each catch block yourself.

// Issue a notice/warning/whatever from a PDOException error message
function my_pdoerror($PDOException) {
   trigger_error($PDOException->getMessage(), E_USER_NOTICE);
}

try {
  // something with PDO
}
catch (PDOException $e) {
   // Call this in your catch blocks.
   my_pdoerror($e);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消