Jump to content

mysql connect or die question


calabiyau

Recommended Posts

Okay i'll give you a little background of what I'm trying to do here.  I have a friend who works for a lighting company.  They wanted to have an online submission form on their site for people to sign up for an upcoming conference.  I told them I could do that pretty easily in php, but soon found out their host does not have php installed.  So my solution was I would set up a database on my own space and host the handling script for their form, so the customers would be briefly redirected to my site from the form where I would process it and then send them back to the site, none the wiser that they've left.  So I've had this company set up two extra pages, one for successful database insertion and one for failure.  In case the database server goes down, I want them to be politely sent to a page that says so instead of getting confusing errors messages

If I do

if (mysql_connect)
{ header("location: succes.htm"}

else
{ header("location: failurre.htm"}

will this work if the databases are down, or will they get stuck on my page with ugly error messages.

If this won't work, I know there is the  (or die) option.  but can I insert the header command into the or die part to direct them to the correct error page, or does that just take a string message?

Thanks.

Link to comment
Share on other sites

mysql_connect() returns a link resource if connected or false on failure so what you could concievably do is
[code]
<?php
if (mysql_connect(mydatabase) != false) //because it does not return true just a link identifier
{ header("location: succes.htm"}

else
{ header("location: failurre.htm"}
?>
[/code]
this would try and connect to the database, if it was successfull it would go to success.php and failure would go to failure.php, you could then run through the connect script properly
Link to comment
Share on other sites

[quote]
Quote
if (mysql_connect(mydatabase) != false) //because it does not return true just a link identifier

Everything except false is considered true in php, so the op's snippet is just as effective.
[/quote]
thanks for that Thorpe learn something new everyday so if its not explicitly false its TRUE ..
but with the Ops post he did not specify a database to check the link to just the mysql_connect command, would you not need it to try and connect to a specific database??
Link to comment
Share on other sites

Yes, I was being short and sloppy I might add with the code I posted.  Sorry about that.  So as I have it, it should work then?  It's just this is the first company i've really done any work for and they are less than happy about being taken off the site so the last thing they want is for their customers to be stuck on someone else's page with all kinds of cannot connect errors.  But as I have it, even if the errors are printed to the screen, the else clause will still send them off to the correct page before they would even get to read them right?
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.