Req #74010 [Com]: add fields to PDOException

From: Date: Sat, 04 Feb 2017 23:00:57 +0000
Subject: Req #74010 [Com]: add fields to PDOException
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-207170@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74010&edit=1

 ID:                 74010
 Comment by:         wowkise at gmail dot com
 Reported by:        wowkise at gmail dot com
 Summary:            add fields to PDOException
 Status:             Open
 Type:               Feature/Change Request
 Package:            PDO Core
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2017-02-01 17:34:02] 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-01-28 15:58:50] 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.





------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=74010&edit=1


Thread (4 messages)

« previous php.bugs (#207170) next »