开发者

PDO: error handling

I am working with PDO in PHP.

Now I wonder if you could catch any global error and show.

With global I mean if any $sql=$connect->prepare() fails, then echo out

"Something went wrong:" . the开发者_JS百科_error

Or would you need to always do it invidually each $sql ?


You can do it using PDO::errorInfo()

http://www.php.net/manual/en/pdo.errorinfo.php

That's about as global as youre going to get.


You could always catch exceptions thrown by the PDO class.

try
{
    ...new PDO('odbc:SAMPLE', 'db2inst1',...
}
catch(PDOException $exception)
{
    echo "Failed: " . $exception->getMessage();
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜