RE: [PHP-WIN] How to Show my Own Error Message Instead of Mysql Error?
| From: | Ross Fleming | Date: | Fri, 21 Jun 2002 06:44:44 +0000 |
| Subject: | RE: [PHP-WIN] How to Show my Own Error Message Instead of Mysql Error? | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-14327@lists.php.net to get a copy of this message | ||
One additional point to clarify: the @ sign in front of the mysql_query
_suppresses any error/warning that may be generated by PHP. It can be
useful on many occasions in PHP (the example that usually springs to my mind
it opening files, to ensure that a warning is not displayed if the file
couldn't be opened).
Ross
> -----Original Message-----
> From: Christian Leberfinger [mailto:christian@leberfinger.net]
> Sent: 21 June 2002 06:58
> To: Jack; php-windows@lists.php.net
> Subject: RE: [PHP-WIN] How to Show my Own Error Message Instead of Mysql
> Error?
>
>
> Here is a simple solution.
>
> if (!($SQLresult = @mysql_query($SQLquery, $DBresource)))
> {
> echo "Errormessage...";
>
> } //endif
>
>
> Of course you could also check the Errortype [mysql_errno()]
> to be sure, whether it is a duplicate-key-errror.
>
> The cleanest solution is to use an ID-key, such as:
>
> ID, Username, Name, Adress, ..., Somefield
>
> Then, of course you have to check on existing users.
>
> You have to be careful to handle two equal requests
> posted at the same time!
> Martin Towell's code might fail when the same insert-
> request is executed just after he has queried the count(*)
> and before PHP is inserting.
>
> Then PHP thinks, the user doesn't exist [count(*)== 0] and
> the insert fails because of duplicate keys.
>
> -> always check the mysql_error
>
>
> Regards,
>
>
>
> Christian Leberfinger
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>