Post Reply  Post Thread 
mysql_connect - retry connection
freesouljah
Junior Member
**

Posts: 27
Group: Registered
Joined: Jun 2006
Status: Offline
Reputation: 0
Post: #1
Question mysql_connect - retry connection

okay...I am trying something that should be simple...but I can't get it to work...I want this php script to keep trying to connect to mysql (maybe 5 times, with a 1 second lapse between, and then stop if it cannot connect at that point):


Code:
    function dbConnect ( ) {
    
        if ($this->dbconnection == "") {
            $this->dbconnection = mysql_connect($this->dbhost, $this->dbuser, $this->dbpass, true);
            mysql_select_db($this->dbname, $this->dbconnection);
            print (mysql_error($this->dbconnection));
        }
    }


I looked around and fiddled with some stuff using tips/ideas from here and here...but I can't get it to work for me...

can you help a brother out?

thanks
Icon_v


08-02-2006 09:29 AM
Visit this user's website Find all posts by this user Quote this message in a reply
freesouljah
Junior Member
**

Posts: 27
Group: Registered
Joined: Jun 2006
Status: Offline
Reputation: 0
Post: #2
RE: mysql_connect - retry connection

nevermind....this works for me:

Code:
<?php
function dbConnect()
{
    if ($this->dbconnection == "")
    {
        for ($i = 0; $i < 5; $i++)
        {
            $this->dbconnection = mysql_connect($this->dbhost, $this->dbuser, $this->dbpass, true);
            $errno = mysql_errno();
            if ($errno == 1040 || $errno == 1226 || $errno == 1203)
            {
                sleep(1);

            }
            else
            {
                break;
            }
        }
        
        if ($this->dbconnection)
        {
                mysql_select_db($this->dbname, $this->dbconnection);

        }
        else
        {
            //return an error possibly?
        }
    }
}
?>


08-05-2006 11:40 AM
Visit this user's website Find all posts by this user Quote this message in a reply
carlyse_09
Junior Member
**

Posts: 3
Group: Registered
Joined: Jan 2009
Status: Offline
Reputation: 0
Post: #3
RE: mysql_connect - retry connection

I'm happy to read that you already found the solution to your problem.Can you share what you do to make it work.


your birth stone
01-13-2009 07:11 AM
Find all posts by this user Quote this message in a reply
freesouljah
Junior Member
**

Posts: 27
Group: Registered
Joined: Jun 2006
Status: Offline
Reputation: 0
Post: #4
RE: mysql_connect - retry connection

carlyse_09 Wrote:
I'm happy to read that you already found the solution to your problem.Can you share what you do to make it work.


the code that works is in the 2nd post... Icon_v


01-13-2009 10:36 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: