Req #74010 [Opn]: add fields to PDOException

From: Date: Wed, 01 Feb 2017 17:34:03 +0000
Subject: Req #74010 [Opn]: add fields to PDOException
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-207106@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 Updated by: adambaratz@php.net Reported by: wowkise at gmail dot com -Summary: PDOException Improvements +Summary: add fields to PDOException Status: Open Type: Feature/Change Request Package: PDO Core -PHP Version: 7.1.1 +PHP Version: Irrelevant Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#207106) next »