When coding the connection part of a php page, I have it so if the connection fails, it gives my special message saying: too many connections, try again later.

This is what I use, and it will show the message when it cannot connect, but then it stops showing the rest of the page after that:

if (!@mysql_connect ($server, $db_user, $db_pass))
exit("Unable to connect, please try later.");

How can I have it so if the connection fails, it gives my message, stops the php/mysql connection/commands, but yet shows the rest of the page? exit and die both halt displaying the rest of the page. Add something to the function? Use another function?

Thanks in advance.

- The Maxx

    You need to do something like this:

    <?php
    $conn = connect("parmsgohere");
    if ($conn){
      CODE GOES HERE;
    } else {
      print "looks like we're outta database connections at the moment";
    }
    
    ?>
    
    HTML GOES HERE
    
    
    

      😃 Of course it would be something simple like that! 😃

      🙂 Thanks 🙂

        Or, you could even do something like this:

        mysql_connect ($server, $db_user, $db_pass) or die("Unable to connect, please try again later");

          This might give you the results you want:

          <?php
          @mysql_connect($hello) or print("connection failed");
          echo "<P> on we go...";
          ?>
          

            I like the if connect, php goes here, else, can't connect, then html,
            but then all the php would be in an if, and might be confusing.

            Pretty sure that the connect or die idea will make the rest of
            the page not load if it can't connect, same as if ! connection, exit.

            Aha! I like the connect or print can't connect. I don't think this
            will stop the loading of the rest of the page and seems simple!

            Thank you all for the brainstorming! 🙂 😃 😉 🆒 :rolleyes:

            - The Maxx

              Write a Reply...