0

I am trying to connect to MySQL on a LAMP instance. If I run

$mysqli = new mysqli("localhost", "user", "pass");
if ($mysqli->connect_errno) {
      die("Connection error: " . $mysqli->connect_error);
}

I only receive the connection error

No such file or directory.

This is the information I get from phpinfo():

phpinfo()

When I try changing localhost to 127.0.0.1 or if I add the port as follows localhost:3306 or 127.0.0.1:3306 the error changes to 'Connection refused'. The LAMP instance is running on a remote server by my company where I do not have any root access. Do you have an idea what I could do to fix the MySQL connection?

EDIT: This question is not the same as for example this question since I do not have root access on the server where the MySQL instance is on. Therefore I cannot use the regular tricks to check whether mysql.sock is in the right place etc. I am pretty sure that the server's settings are correct, I just need help finding out how to write my MySQL-connection correctly.

ec-m
  • 779
  • 1
  • 5
  • 15
  • 1
    I've changed the user and pass in the question to prevent whatever there is to be prevented... – FirstOne Dec 20 '17 at 13:56
  • 1
    `No such file or directory.` doesn't seem like a connection error to me. – Jonnix Dec 20 '17 at 13:57
  • _The LAMP instance is running on a remote server_ If you mean that the MySQL that you are trying to connect to is on a remote machine then `localhost` and `127.0.0.1` are not what you want in your connection. They indicate ___the machine I am currently running my PHP code on___ – RiggsFolly Dec 20 '17 at 13:58
  • Or is your code also running on the _Remote Server_? – RiggsFolly Dec 20 '17 at 13:59
  • In which case, is your MySQL instance on the same machine as your web server and the PHP code – RiggsFolly Dec 20 '17 at 14:00
  • @RiggsFolly Yes, the MySQL instance and the PHP code are on the same server. – ec-m Dec 20 '17 at 14:15
  • Then it looks like the Dup answer is what you are looking for – RiggsFolly Dec 20 '17 at 14:16
  • there are *many* answers in the linked thread. try different suggestions. You don't need root privileges to find out the path to mysql socket. if you need to connect with localhost, there are no whatever "correct" credentials other than localhost and 127.0.0.1. Stop blaming everyone else and start looking for the solution. – Your Common Sense Dec 20 '17 at 14:23
  • 1
    This answer appears to be directly applicable to you and doesn't require root permissions. https://stackoverflow.com/a/10958016/310988 –  Dec 20 '17 at 15:03

0 Answers0