Errorhandling

DAL provides a general way for errorhandling. When a function fails DAL returns 'false' when it's no result function or NULL when the function has to produce a result. It also calls it's own error-handler which puts the errormessage in an internal variable. You can look at the value of this variable or customize the error-handling.

Getting the errormessage

When an error occurs DAL saves the error in an internal variable. You can get this errormessage by fetching the value of lastError. This gives you a plain-text message which should explain which error occured.

Using your own error handler

DAL also gives you the posibillity to customize the error-handler. That means you can use you're own handler to process the error. By example if you want to have the errormessage mailed to you this is the way to let DAL do that. Just create your own function and say to DAL it has to call it instead of it's own handler.

Your function has to comply to the following prototype:

boolean funtionName(string errorMessage);

To tell DAL that it has to use your handler instead of it's own you call the funcion setErrorHandler. This function takes as parameter the name of your error-handler. Below you see a little example. A complete example can be found here.

 	/*
	 * My error Handler
	 */
	 function myErrorHandler($errorMessage) {
	   /*
		  * In here we handle the error.
		  */
	 }

	 $mydb = new dal;
	 $mydb->setErrorHandler("myErrorHandler");
	

Important

Because DAL doesn't handle the errors anymore lastError won't contain any errors. When you want to look at the errors later on you have to make sure you save it somewhere.