holowugz Posted March 28, 2006 Share Posted March 28, 2006 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 Quote Link to comment Share on other sites More sharing options...
lpxxfaintxx Posted March 28, 2006 Share Posted March 28, 2006 Hrmm. I've been wondering about this too. Quote Link to comment Share on other sites More sharing options...
txmedic03 Posted March 28, 2006 Share Posted March 28, 2006 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. Quote Link to comment Share on other sites More sharing options...
holowugz Posted March 28, 2006 Author Share Posted March 28, 2006 That is fantastic, exactly what i was looking for thankyou very Much. Quote Link to comment Share on other sites More sharing options...
trq Posted March 28, 2006 Share Posted March 28, 2006 If your using php5 you might also want to look into using exceptions. Its a much eaiser / neater way of handling errors. Quote Link to comment Share on other sites More sharing options...
holowugz Posted March 28, 2006 Author Share Posted March 28, 2006 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. Quote Link to comment Share on other sites More sharing options...
txmedic03 Posted March 29, 2006 Share Posted March 29, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.