Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP & MySQL: Can't connect to MySQL server

  • 16-03-2011 8: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,496 ✭✭✭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