A few eeks ago, an old customer came back to me asking for a way to manage PostgreSQL errors in PHP, this is because he has a PHP web based system with access to a PostgreSQL database.
Now, as many other PHP web-based systems out there, the error exposure is enabled, thus, every time a query returns an error, it was printed in web page, which as you can think, is not a good thing.
Now, in order to avoid this you can easily go to the php.ini file and change the display_errors directive from On to Off and enable the error logging. But, how to catch the errors and display them in a friendly manner to customer? With this workaround, nothing will be displayed and customer won't have a clue of what's going on, oh well, yes, because its data may not be displayed.
So a little solution has been implemented with the following code:
INSERT CODE HERE
Ok, let's explain: as you should know there is a set of common error codes in SQL, and specifically, for PostgreSQL there is a well explained section of its docummentation.
As you may infer, the SQL error code 23505 (UNIQUE VIOLATION) may appear whenever a violation of a unique constrain occurs, no matter in what table it happens so, in order to create a customized message, system must be aware of who (what page) requested that operation.Is not the same thing a UNIQUE VIOLATION from the add page than from the modify page, neither if it happens in the users module or the customers module.
In order to customize errors the sqlErrorCodes.php file has been created, it contains, as an array, all the possible errors that can be
Now, as many other PHP web-based systems out there, the error exposure is enabled, thus, every time a query returns an error, it was printed in web page, which as you can think, is not a good thing.
Now, in order to avoid this you can easily go to the php.ini file and change the display_errors directive from On to Off and enable the error logging. But, how to catch the errors and display them in a friendly manner to customer? With this workaround, nothing will be displayed and customer won't have a clue of what's going on, oh well, yes, because its data may not be displayed.
So a little solution has been implemented with the following code:
INSERT CODE HERE
Ok, let's explain: as you should know there is a set of common error codes in SQL, and specifically, for PostgreSQL there is a well explained section of its docummentation.
As you may infer, the SQL error code 23505 (UNIQUE VIOLATION) may appear whenever a violation of a unique constrain occurs, no matter in what table it happens so, in order to create a customized message, system must be aware of who (what page) requested that operation.Is not the same thing a UNIQUE VIOLATION from the add page than from the modify page, neither if it happens in the users module or the customers module.
In order to customize errors the sqlErrorCodes.php file has been created, it contains, as an array, all the possible errors that can be
No hay comentarios.:
Publicar un comentario