Php – thesql_connect doesn’t work on a certain host

MySQLPHP

I get this everytime I use mysql_connect() no matter what database I choose:

Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'IP' (111) in filename.php on line 17
A MySQL error has occurred: Can't connect to MySQL server on 'IP' (111)

The exact same file works on my personal website fine. I have tried multiple databases hosted on different servers and it always gives that output.

The database itself is hosted on the same server, but using its full IP in mysql_connect(). Using localhost:port doesn't work either as it says:

Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in filename.php on line 17
A MySQL error has occurred: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

But using the IP should work as it has worked calling it via the same file hosted on other servers.

This is the code:

    $connect = mysql_connect($db_url,$db_user,$db_pass); // connects
    if ($connect == false) exit("A MySQL error has occurred: " . mysql_error());

Now since the file works on other servers i am guessing it is something to do with the server it is on and might need something changed. I don't personally have root access to the server (just my part of the shared host). Is there anything I can do i php, editing the php.ini file or something I should pass on to someone with root access?

Edit: Ok it turns out that the server doesn't have access to outside databases, so thats why the IP didn't work. Thanks for all your answers but we have decided simply to change hosting provider. We need to be able to access an outside database.

Best Answer

This is on a hosting service? Check their documentation, there will be something that tells you where to find mysql. It isn't necessarily localhost.

For example, on startlogic.com, you use: yourdomain.startlogicmysql.com