Reply to Re: database exception message to user-end information

Your name:

Reply:


Posted by Yarco on 08/20/07 05:42

But other Exception may also be thrown in adding record process...

On Aug 16, 10:51 pm, burgermeiste...@gmail.com wrote:
> On Aug 16, 2:38 am, Yarco <yarc...@gmail.com> wrote:
>
>
>
> > When i am coding something, i always need to do some error control on
> > it.
> > For example:
>
> > <?php
>
> > function check()
> > {
> > // the following vars from somewhere
> > if (empty($username))
> > {
> > $error['username'] = 'empty user name';
> > return false;
> > }
> > if (//...)
> > {
> > }
> > return false;
>
> > }
>
> > try
> > {
> > // to add a record}
>
> > catch(Exception $e) // but failed, because you can't add record again
> > some column is uniq.
> > {
> > $error['db'] = $e->getMessage();
>
> > }
>
> > ?>
>
> > So $error will contain something like:
> > 'db' => "SQLSTATE[23000]: Integrity constraint violation: 1062
> > Duplicate entry '1-5' for key 'rate_guid_accountId'"
>
> > But i want to let user know they do not do such thing but now such
> > professional words.
> > How can i do it?
>
> A good approach I've used in the past is to have two arrays for error
> message; one for developers and one for users. Then you can do
> something more like this:
>
> try
> {
> // to add a record
>
> }
>
> catch(Exception $e) // but failed, because you can't add record again
> some column is uniq.
> {
> $dev_error['db'] = $e->getMessage();
> $user_error['db'] = "I'm sorry, that user name is already taken.
> Please try again.";
>
> }
>
> That way in your debugging output you can see exactly what went wrong
> and at the same time you can have a more friendly message for end
> users, and without giving away too many details.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация