php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #74010 add fields to PDOException
Submitted: 2017-01-28 15:58 UTC Modified: 2017-10-24 08:32 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: wowkise at gmail dot com Assigned:
Status: Open Package: PDO related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: wowkise at gmail dot com
New email:
PHP Version: OS:

 

 [2017-01-28 15:58 UTC] wowkise at gmail dot com
Description:
------------
I would like the possibility of improving PDOException to include the query string and bind parameters if available, for example.

$sql = 'select foo from bar fail';
$bind = [];
$pdo = 'pdo instance';
$pdo->query($sql,$bind);

set_exception_handler( function ( \PDOException $e) {
    var_dump( $e->queryString, $e->queryBind);
} );

now you might ask why i would need such thing, i personally use set_exception_handler to handle all logging in production and we sometimes have case of failed queries, and to produce good reports we need access to the queryString and the bind data if available, and i was planing on making generic class for handling all these cases.

but it's impossible to get the pdo instance if the class is generic, what i've done so far is to have a generic class that run on top of pdo and catch the PDOException and wrap them in another instance of Exception that extends PDOEXception that has special methods such (getQuery() and getBind() ), while this works if i can control the whole app, it's become really hard to release something to the public that works out of the box with PDO, without having to wrap all those class.




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-02-01 17:34 UTC] adambaratz@php.net
-Summary: PDOException Improvements +Summary: add fields to PDOException -PHP Version: 7.1.1 +PHP Version: Irrelevant
 [2017-02-01 17:34 UTC] adambaratz@php.net
That's an interesting use case. Since this is an API change, there should be an RFC so the broader community can talk through any edge cases. See here for details:
https://wiki.php.net/rfc/howto
 [2017-02-04 23:00 UTC] wowkise at gmail dot com
Hi thanks for your interest, My English skills aren't good enough to explain fully what i want in RFC, and i really don't know how to implement this feature in C as i am only PHP dev. 

If you could take the lead i'll be grateful if not, i'll try to find someone to champion this feature.
 [2017-10-24 08:32 UTC] kalle@php.net
-Package: PDO Core +Package: PDO related
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Jul 21 11:01:25 2019 UTC