Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error handling

Status
Not open for further replies.

martinm

IS-IT--Management
Joined
Mar 30, 2001
Messages
113
Location
GB
Hi all - new to PHP, but migrating some VBScript nicely!

However, I'm having problems with the err handler.


function user_error_handler($severity, $msg)
{
$err_description = $msg;
}

$old_error_handler = set_error_handler('user_error_handler');


This doesn't seem to be called when I have an error (n this case, getting a non-existent record from MySQL.

I've tried

error_reporting(E_WARNING);
error_reporting(E_ALL);
error_reporting(E_WARNING | E_ERROR);


Ta.
 
you need to restart the webserver for changes to the PHP ini to take effect.

E_ALL shoprovide a little too much detail, but iuts very useful while you find your feet

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Getting a non-existent record from MySQL is not an error.

If I invoke a query such as:

SELECT * FROM tablename WHERE columnname = 3

and no records match, there is no error, but rather a return of an empty resultset.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Sleipnir - I guess was a bit vague - it's asking for the first row from the resultset that is the error (warning).

KarveR - I'm not making any changes to PHP.ini or am I?!!

Thanks.
 
wack your code on to here for us to have a look at.
KarveR: Do you need to restart the web server if your in CGI mode ?
 
Good question ingresman, one I hadn't taken into account :-)

martinm, how else are you setting your error reporting options I presumed (wrongly or rightly) that you were setting the error reporting within the php.ini.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Code!!

Note the error_reporting() at the top Not changing PHP.ini or anything else.

Ta.


<?php

error_reporting(E_WARNING);

// Sets up the MySQL stuff. Works!!!
require("connect2db.php");

function user_error_handler($severity, $msg)
{
$err_description = $msg;
}

$old_error_handler = set_error_handler('user_error_handler');

set_time_limit(0);
//On Error Resume Next

$SIDPassed = $_GET["SID"];

$result = mysql_query("SELECT userID FROM tblUserModuleProgress WHERE userModuleProgressID = $SIDPassed" ,$db);

$userID = Trim(mysql_result($result,0,"userID"));

if (empty($err_description))
{
print("ErrorStatus = 0");
print("ErrorMessage = UserID returned OK ");
} else {
print("ErrorStatus = 1");
print("ErrorMessage = Error returning userID ");
print("aspErrorDescription = $err_description ");
}

?>
 
I suggest you read the FAQ on retrieveing dtaa from MySQL:
faq434-3850
 
DRJ - the data retrieval is OK, just that I expect an error (and do get one, but it doesn't run my handler) if I try

$userID = Trim(mysql_result($result,0,"userID"));

when no data was returned.

Will this not raise an error?

I've tried (with error_reporting(E_ALL);)

trigger_error ("Cannot divide by zero", E_USER_ERROR);

Still no luck :(
 
You are looking in the back garden for the front door.

If its a PHP script error, PHP's error handling will show it, if you are looking for a MySQL error, you'll need to trap the output from MySQL and direct that to your function.

mysql_error() and mysql_errno() will help you.



______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Cheers - I'll use that. Still can't work out why raising an error myself doesn't work tho!
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top