Jump to content

Archived

This topic is now archived and is closed to further replies.

holowugz

Custom MYSQL error pages

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
If your using php5 you might also want to look into using exceptions. Its a much eaiser / neater way of handling errors.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.