Jump to content


Photo

Custom MYSQL error pages


  • Please log in to reply
6 replies to this topic

#1 holowugz

holowugz
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 28 March 2006 - 02:26 AM

ok on vBulletin when there is a MYSQL error a lovely little custom error page comes up which details some of the problems and sends a report to the admin.

is there anyway when there is a MYSQL error i can redirect the page? to another script or something

#2 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 28 March 2006 - 02:32 AM

Hrmm. I've been wondering about this too.

#3 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 28 March 2006 - 03:42 AM

Most assuredly yes. Now the question is how exactly your page is formatted as to how to proceed. If no output has yet been generated you can use header("Location: {url}"). If this method will not work for you I could make other suggestions such as embedded errors or other methods of redirection, but for now we will just use header().

<?

$conn = mysql_connect('localhost', 'username', 'password') or header("Location: mysql_error.php?err=".urlencode(mysql_error()));

?>

This attempts a connection to the server and if an error is encountered it redirects to a page to display the error.

On the mysql_error.php page you need to decode the error and display it how ever you like. I'm not sure exactly what you want to do with it so I really can't be too specific here.

<?

$mysql_error = urldecode($_GET['err']);

?>

This may not be the method you want to use, but I hope I have at least pointed you in the correct direction.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.


#4 holowugz

holowugz
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 28 March 2006 - 10:05 AM

That is fantastic, exactly what i was looking for thankyou very Much.

#5 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 28 March 2006 - 12:44 PM

If your using php5 you might also want to look into using exceptions. Its a much eaiser / neater way of handling errors.

#6 holowugz

holowugz
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 28 March 2006 - 01:52 PM

Just out of interested how would the embedded error work.

because MOST of my MYSQL querys are done before any information is output so that is ok.

but there is about 3 MYSQL querys that are run after there is output to the screen so i couldnt do a header redirect.



#7 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 29 March 2006 - 01:25 AM

Well the embedded error will depend greatly on the way you layout your code. You could simply do a or die("formatted error result"); at the end of your mysql commands.

There are a couple of ways of doing this and getting the results you want, but it all depends on the layout of your code. This is just one basic example, but more then likely it isn't exactly what you are looking for. You could simply create a $header and $footer for the beginning and end of all your error strings to save yourself from typing lots of xhtml.

Additionally, unless the server you intend to use specifically supports PHP5 then you should design based on PHP4. If your server does support PHP5 then you may want to check into thorpe's response.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users