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: 2021-08-04 15:00 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: Suspended Package: PDO related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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
 [2021-08-04 15:00 UTC] cmb@php.net
-Status: Open +Status: Suspended
 [2021-08-04 15:00 UTC] cmb@php.net
Since this requires an RFC, I suspend this ticket for the time
being.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Sep 27 02:03:36 2021 UTC