Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

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

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

  1. cloudkicker

    cloudkicker Registered

    Nov 16, 2007
    Likes Received:
    Trophy Points:
    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

    class DB {

        private static 

        public function 
    __construct() {
            if (
    $handle mysql_connect(DB_HOSTDB_USERDB_PASS)) {
    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();

    // some code...

  2. jayh38

    jayh38 Well-Known Member

    Mar 3, 2006
    Likes Received:
    Trophy Points:
    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

    Feb 28, 2007
    Likes Received:
    Trophy Points:
    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.
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice