 |
|
 |
|
Next: Security Warning message Windows
|
| Author |
Message |
External

Since: Dec 19, 2004 Posts: 4
|
(Msg. 1) Posted: Sun Feb 20, 2005 6:40 am
Post subject: How to catch mysql_connect errors ? Archived from groups: alt>php>sql (more info?)
|
|
|
I would like to prevent mysql_errors from displaying on screen in my
php-pages. The users dont need those, they only need to know in plain
english that there was an error while connecting to the database, I will
then log the the real error to file.
Only part of the code is displayed and a bit simplified (I made a class for
connecting and querying databases) :
This doesnt work (it works OK but the mysql.error message is displayed on
screen before the $ErrMessage)
$LinkID = mysql_connect($arrConnect["host"], $arrConnect["user"],
$arrConnect["pass"]);
if (!$LinkID)
{
$ErrMessage = "Error occured while connecting to database.";
echo ($ErrMessage . "<br>\n");
$ErrLogging = __CLASS__ . " - " . __FUNCTION__ . " - " . $ErrMessage
.. mysql_error();
LogMessage($ErrLogging);
...
When I use mysql_connect or Die() it never reaches the if-statement.
It works OK for mysql_select_db
$Result = mysql_select_db($arrConnect["db"], $LinkID);
if (!$Result)
{
$ErrMessage = "Error occured while selecting database.";
echo ($ErrMessage . "<br>\n");
$ErrLogging = __CLASS__ . " - " . __FUNCTION__ . " - " . $ErrMessage
.. mysql_error();
LogMessage($ErrLogging);
return;
...
It works OK for mysql_query
$Result = mysql_query($sqlquery, $LinkID);
if (!$Result)
{
$ErrMessage = "Error occured while executing query.";
echo ($ErrMessage . "<br>\n");
$ErrLogging = __CLASS__ . " - " . __FUNCTION__ . " - " . $ErrMessage
.. mysql_error();
LogMessage($ErrLogging);
return;
...
thanx,
Pugi! >> Stay informed about: How to catch mysql_connect errors ? |
|
| Back to top |
|
 |  |
External

Since: Dec 01, 2003 Posts: 190
|
(Msg. 2) Posted: Sun Feb 20, 2005 6:40 am
Post subject: Re: How to catch mysql_connect errors ? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Pugi! wrote:
> I would like to prevent mysql_errors from displaying on screen in my
> php-pages. The users dont need those, they only need to know in plain
> english that there was an error while connecting to the database, I will
> then log the the real error to file.
> Only part of the code is displayed and a bit simplified (I made a class for
> connecting and querying databases) :
>
> This doesnt work (it works OK but the mysql.error message is displayed on
> screen before the $ErrMessage)
> $LinkID = mysql_connect($arrConnect["host"], $arrConnect["user"],
> $arrConnect["pass"]);
> if (!$LinkID)
> {
> $ErrMessage = "Error occured while connecting to database.";
> echo ($ErrMessage . "<br>\n");
> $ErrLogging = __CLASS__ . " - " . __FUNCTION__ . " - " . $ErrMessage
> . mysql_error();
> LogMessage($ErrLogging);
> ...
> When I use mysql_connect or Die() it never reaches the if-statement.
Use @ infront of functions that you want to prevent to make an output to
"html", otherwise you can set a setting in php.ini to not display error
messages in "html", but see to enable error logging, so you have a chance to
see what went wrong.
//Aho >> Stay informed about: How to catch mysql_connect errors ? |
|
| Back to top |
|
 |  |
External

Since: Dec 19, 2004 Posts: 4
|
(Msg. 3) Posted: Sun Feb 20, 2005 7:40 am
Post subject: Re: How to catch mysql_connect errors ? [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
"J.O. Aho" schreef in bericht
> Pugi! wrote:
>> I would like to prevent mysql_errors from displaying on screen in my
>> php-pages. The users dont need those, they only need to know in plain
>> english that there was an error while connecting to the database, I will
>> then log the the real error to file.
When I use mysql_connect or Die() it never reaches the if-statement.
>
> "html", otherwise you can set a setting in php.ini to not display error
> messages in "html", but see to enable error logging, so you have a chance
> to see what went wrong.
>
>
> //Aho
Thanx, the @ works perfect for my needs.
Pugi! >> Stay informed about: How to catch mysql_connect errors ? |
|
| Back to top |
|
 |  |
| Related Topics: | mysql_connect and private user function - Hi, got a bit stuck whit this... I have page where I connect to database and it works fine, but when I try to do it in my own function, I get error. my code: ----------------------------------------------- //connect to database... $con =..
mbstring, mcrypt, php4ts and other errors - I know this is a lot but it is the culmination of 5 days of cold sweaty fear and neck cringing frustration. The following is installed in my Windows XP (Home Version 2002, Service Pack 2) machine. Please bear in mind I installed all of this accordin...
PHPtriad v2.2.1 removal - When I fist started using apache/php/mysql I used phptriad [a wonderful piece of kit] to get me up and running. I've used this ever since. I'm think inow of 'upgrading' to laters versions of all three applications, and have found various tutorials/Ho...
MySQL regular expression to match a imploded item - Hello I need to use MySQL's REGEXP (POSIX compliant) to search registries where one field is an imploded set of integer values separated with pipes "|". I need to match one of these imploded values directly on a sql select. $sql = "SELECT...
Weird mysql_connect problem - Hello. My mysql_connect just started to give me following error today, Fatal error: Call to undefined function: mysql_connect() in ..../database_functions/db_functions.inc.php on line 11. So it seems that my php no longer finds php-mysql module... |
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|
 |
|
|