The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Mysterious "mysql_connect()" Problem (PHP/MySQL)

Discussion in 'General Discussion' started by cloudkicker, Nov 16, 2007.

  1. cloudkicker

    cloudkicker Registered

    Joined:
    Nov 16, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Hello all,

    I have come across a wierd problem while trying to connect to a remote database.

    Currently, my PHP scripts are located on a shared hosting server (Siteground). My remote MySQL database is located on another shared hosting server (Hurricane Electric).

    When trying to execute the connection via mysql_connect, the server will attempt to establish a connection until the request times out, at that point causing the script to halt. I have also tried mysqli to connect just for kicks, also resulting in a timeout. To avoid confusion, I am trying to access my database on another server, while having my scripts on Siteground's web server the remote database, not the other way around :)

    The mysterious part of this is that when I run my connection script on my local development server, I can connect to my remote database successfully.

    I have this strange feeling that Siteground may be blocking TCP/UDP port 3306 for my mysql_connect to my other database server. Can anyone verify this?

    Any suggestions you can throw at me is much appreciated! :D

    PHP:
    class DB {

        private static 
    $link;

        public function 
    __construct() {
            if (
    $handle mysql_connect(DB_HOSTDB_USERDB_PASS)) {
                
    mysql_select_db(DB_NAME);
                
    self::$link $handle;
            }
            
    /*
            if ($handle = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME)) {
                self::$link = $handle;
            }
            */
            
    else {
                throw new 
    Exception("Failed to connect to DB: " mysql_error() . "\n");
            }
        }
        
        public static function 
    getDCon() {
            if (!
    is_object(self::$link)) {
                
    self::$link = new DB();
            }
            return 
    self::$link;
        }

    // some code...

    }  
     
  2. jayh38

    jayh38 Well-Known Member

    Joined:
    Mar 3, 2006
    Messages:
    1,215
    Likes Received:
    0
    Trophy Points:
    36
    It appears port 3306 is most likely behind their firewall. You could ask for a pass through if its a good host. I do the same on my servers and pass the client through per request.

    The connection script does not actually test port 3306, it merely sets up the access host via your whm root.
     
  3. gtgeorge

    gtgeorge Well-Known Member

    Joined:
    Feb 28, 2007
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    6
    Did you add the ip for siteground to the allowed hosts for the db on Hurricane Electric? If you did you will need to contact them to allow the connection.
     
Loading...
Similar Threads - Mysterious mysql_connect() Problem
  1. nhadsall
    Replies:
    2
    Views:
    448

Share This Page