Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP & MySQL: Can't connect to MySQL server

  • 16-03-2011 09:49PM
    #1
    Closed Accounts Posts: 4,001 ✭✭✭


    Hi all

    This is probably a very simple question, and I'm sure there is a simple answer, but it's been a while since I did this and can't figure it out.

    I have the following code:

    [PHP]
    $link = mysql_connect('server.com', 'username', 'password');
    if (!$link) {
    die('Could not connect: ' . mysql_error());
    }
    $db_selected = mysql_select_db('database', $link);
    [/PHP]

    This code works fine if I run it on the server where MySQL is installed, but if I try to run it on a remote server I get the following error:

    PHP Warning: mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Can't connect to MySQL server on 'server.com' (4) in /home/account/public_html/script.php on line 1

    Is there some permission on MySQL which is disallowing remote connections?

    Note I have added the remote server (where I want to run the script) to the list of "allowed hosts" in cPanel where MySQL is installed.

    Anyone have any ideas?

    Cheers


Comments

  • Closed Accounts Posts: 9,495 ✭✭✭Mr. Presentable


    My experience with remote connections in SQL is limited, but did you allow remote connections in COM/Security on the host?


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Firewall?


  • Registered Users, Registered Users 2 Posts: 171 ✭✭conorcan2


    Did you specify the port?

    e.g. server.com:3306


  • Closed Accounts Posts: 4,001 ✭✭✭Mr. Loverman


    Hi all

    Thanks for the replies.

    Ipchains was blocking the remote server's IP.


Advertisement