Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Senior Member medlington's Avatar
    Join Date
    Nov 2005
    Location
    Sheffield, UK
    Posts
    377
    Member #
    11968
    Liked
    4 times
    Hi,

    I have a hosting setup where the DB is stored on a different server and so is not accessed by 'localhost'.

    the problem I get is that the DB seems to be on a busy server and quite often it fails to connect at the first attempt.

    What Im trying to do is get the script to try again or maybe even 2 or 3 times untill I get a successfull connection.

    The script Im using to acess the DB is:

    PHP Code:
    $conn mysql_connect($dbhost$dbuser$dbpass) or die('Error connecting to mysql');
    mysql_select_db($dbname); 
    Can I just change the OR DIE part to something along the lines of
    PHP Code:
    $conn mysql_connect($dbhost$dbuser$dbpass) or mysql_connect($dbhost$dbuser$dbpass);
    mysql_select_db($dbname); 
    or should I have this in a loop that keeps trying untill its successfull. I realise this could lead to bad things happening though.

    Thanks

  2.  

  3. #2
    Junior Member jeffatrackaid's Avatar
    Join Date
    Jul 2010
    Location
    Jacksonville, FL
    Posts
    11
    Member #
    22560
    I am not a programmer, but the other day while tuning a server for a client, I noticed they had a set of if/then type statements. They basically tried to connect and if it failed it would wait 2-5s and try again.

    if (datbase connect != success)
    then wait 5s
    (if database connect !=success)
    then wait 5s
    fi
    fi

  4. #3
    Junior Member
    Join Date
    Nov 2010
    Posts
    23
    Member #
    24956
    you can also try pinging the server before sending the connection request


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 02:02 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com