Jump to content

Custom MYSQL error pages


holowugz

Recommended Posts

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
Link to comment
Share on other sites

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().

[code]<?

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

?>[/code]

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.

[code]<?

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

?>[/code]

This may not be the method you want to use, but I hope I have at least pointed you in the correct direction.
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Well the embedded error will depend greatly on the way you layout your code. You could simply do a [b]or die("formatted error result");[/b] 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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.