Redirect to new page if there's an MySQL connection error?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Galt
Forum Newbie
Posts: 18
Joined: Thu May 22, 2003 8:08 am

Redirect to new page if there's an MySQL connection error?

Post by Galt »

I have a website that displays a banner on the very top (always), then tries to connect to a MySQL database. I know that if this connection fails, I can't use the header() function to redirect to another page that says something like "sorry, server problems. try again" or something to that effect, since I've already sent data to the client (i.e the banner).

Does anyone have an idea how I can gracefully recover from such a connection error and show another page? Right now I have

Code: Select all

... || die("Can not connect to database");
which to be honest doesn't look professional at all.

Here's what my php code looks like:

< show banner code>
< try to connect to mysql database >
<**would like code here to redirect to new page if conn failed**>
< code to display data retreived from database>

Thanks in advance.
Galt
Forum Newbie
Posts: 18
Joined: Thu May 22, 2003 8:08 am

Post by Galt »

Actually, never mind. I think i'll just move the connection code before the banner code. That should fix it.
Post Reply