473,387 Members | 1,596 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

database exception message to user-end information

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?

Aug 16 '07 #1
2 2022
On Aug 16, 2:38 am, Yarco <yarc...@gmail.comwrote:
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.

Aug 16 '07 #2
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.comwrote:
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.

Aug 20 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: djozy | last post by:
Please,I have made database in Sql server. How to connect with it? It is,lets say,in C:\temp and its name is database1. What do I need to put here: SqlConnection conn=new SqlConnection("Data...
1
by: Azel | last post by:
Hi, I am trying to learn ADO.net and I keep running into problems trying to insert data into my Access Database: data.mdb. here is my code: <code> // Database Variables
12
by: Ann Marinas | last post by:
Hi all, I would like to ask for some help regarding separating the asp.net webserver and the sql server. I have created an asp.net application for a certain company. Initially, we installed...
10
by: vvenk | last post by:
Hello: When I tried to use an Access database, I get the following exception: Server Error in '/WebGrid' Application....
4
by: Mark | last post by:
I'd like to take an instance of a class and store it in a database. I've marked my class as and am using the binary formatting code similar to...
2
by: Mark | last post by:
Hi, I don't have a code problem. I have an understanding problem. This is a made up situation that mimics my real situation but it is easier to understand. 1. I call a web method with an...
7
by: Susan Mackay | last post by:
I have a data table that is connected to a database table with a data adapter in the 'standard' manner. However I want to be able to remove selected rows from the data table (i.e. no longer...
2
by: astolpho | last post by:
I am using a slightly outdated reference book on J2EE programming. It gives 2 methods of creating a database used in its casestudies. The first is an ANT script that gives the following output: ...
3
by: Michael Schöller | last post by:
Hello, First of all english is not my natural language so please fogive me some bad mistakes in gramatic and use of some vocables :). I have a great problem here. Well I will not use it...
6
by: =?Utf-8?B?UGFycm90?= | last post by:
I cannot access my SQL database in a browser control created in my C# Windows application program I can, however, access the database from an IE browser. I get the ubiquitous "Login failed for NT...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.