CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 [RESOLVED] Intercepting and managing DB errors

Print topic Send  topic

Author Message
scarvello

Posts: 64
Posted: 10/31/2015, 3:59 AM

Hi all
It's possibile to intercept a DB error like this:

"Database Error: Cannot delete or update a parent row: a foreign key constraint fails ... " and manage it by using a custom message.

I would like to show a custom error message when errors like this occur.
Something like this:

if (DB error occurs) {
$myform->Errors->addError("my message");
}

Tnx in advance
View profile  Send private message
DataDoIT
Posted: 10/31/2015, 6:05 AM

Not using CCS's data connection controller.

* On production systems make certain these types of errors are never
displayed (display_errors = 0 in php.ini) to the end user.

You could wrap your own connection and traps on your form controls to do
the database write, placing your code in the form's
BeforeExecuteUpdate/Insert/Delete events. Then use try and catch. See
https://www.google.com/#q=php+catch+mysql+error

The mysql_error() function will hold any errors from the active
connection. You'll need to figure out a way to capture that before the
form's connection closes, perhaps in the
AfterExecuteUpdate/Insert/Delete event.

$Error = $Page->Connections["Connection1"]->mysql_error();

Regardless, turn off the displaying of any errors to the end user and
monitor the PHP, Apache and MySQL logs on your production systems.
You'll spend more time and effort trying to gracefully capture errors
than you would actually fixing the errors.
scarvello

Posts: 64
Posted: 10/31/2015, 7:13 AM

Thanx DataDoIT,
The errors I would wrap are Constraints Errors formally designed into my ER model.
For example I want to wrap the error that occur when user commit delete of row from a master table into a master-detail relationship. I don't like to use "ON DELETE CASCADE" to automatically delete all rows from the detail table.
CodeCharge,by default, show the MySql Constraint Violation error message if it happen.
I would like to intercept this message, change it with a more appropriate to my business logic and show it in the same way/place that CCS does.
Simply I would like to change message text and leave CCS do all the rest.
I know that there is a way for message customizations directly inside the database server but I'm using an hosted db server and I don't have root access on it.
Any more suggestions?
View profile  Send private message
scarvello

Posts: 64
Posted: 10/31/2015, 7:53 AM

RESOLVED
On AfterExecuteDelete

// Check if DB Errors contain a Foreign key contrsaint violation when deleting a row
if (strpos($myForm->DataSource->Errors->Errors[0],"foreign key constraint fails")>0) {

// Replace with custom message
$myForm->DataSource->Errors->Errors[0] = "My custom Message";

}

Note: A more accurate code must look at all Errors elements
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.