Topic: mysql error redirect?

Hey. The host I use seem to experience alot of (different) mysql errors, which is resulting in the forum being down Way too much - so I am trying to find something that, when a mysql error occurs, a page of my choice comes up (with the mysql error embedded) for instance, the news archive...

I've made the page already, but I don't know how to go about making the redirect.

I found this script, but don't know if it's compatible with punbb, or even where to put it. Anyone have any ideas?


// Here is the function. This function must be placed before any HTML code or 
// else the redirect will not work. You could place it in a separate file and 
// use include. 
function dbconnect($hostname, $username, $password, $database) { 
       $conn = @mysql_pconnect($hostname, $username, $password); // "@" is 
necessary. 
       if(!$conn) header("Location: Forum_error.html"); 
       if(!mysql_select_db($database, $conn)) header("Location: Forum_error.html"); 
} 

// This is how to call the function. This must also be placed before any HTML 
// code or else the redirect will not work. 
dbconnect($host, $user, $pwd, $db);

2

Re: mysql error redirect?

Stating the obvious here, but why don't you change host?

Re: mysql error redirect?

You'd have to look in the different DB abstraction classes (include/dblayer)

Re: mysql error redirect?

Elzar wrote:

Stating the obvious here, but why don't you change host?

I knew someone was going to say that! Because my site is hosted for free (they are non-profit).  It is otherwise an excellent host (better and more trustworthy than every corp host I've had) 

Smartys, I'm sorry, I don't understand what you're saying. If you have a couple moments, could you give me a little more detail?

5 (edited by Smartys 2006-02-27 03:05)

Re: mysql error redirect?

http://dev.punbb.org/file/trunk/upload/ … /mysql.php
Each DB type (MySQL, MySQLi, PostgreSQL, and SQLite) has its own abstraction layer. Just edit the file for the one you're using (the function is DBLayer) to add the redirect in (oh, and to note, after doing Location: headers you should use exit or the script will continue executing without the user seeing the output).
So, as an example for MySQL, the new function would be

        function DBLayer($db_host, $db_username, $db_password, $db_name, $db_prefix, $p_connect)
        {
                $this->prefix = $db_prefix;

                if ($p_connect)
                        $this->link_id = @mysql_pconnect($db_host, $db_username, $db_password);
                else
                        $this->link_id = @mysql_connect($db_host, $db_username, $db_password);

                if ($this->link_id)
                {
                        if (@mysql_select_db($db_name, $this->link_id))
                                return $this->link_id;
                        else
                        {
                                header("Location: Forum_error.html");
                                exit;
                        }
                }
                else
                {
                        header("Location: Forum_error.html");
                        exit;
                }
        }

Re: mysql error redirect?

Thank You so much, Smartys. Now I just have to wait for a mysql error, LOL