Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Database connection problem
09-11-2020, 01:46 AM,
#1
Database connection problem
Hello, having installed webERP, I was unable to log in - the result was always a message

"Connect failed: No such file or directory"

Eventually traced this to the initial mysqli_connect() call, where I put in some debugs to verify that this function was being passed the expected arguments, then suddenly remembered a previous problem I had with mysqli - the solution was to change config.php so that the host is specified not as 'localhost', but as '127.0.0.1'. I think this is something to do with the fact that I am using a non-standard port for the mySQL server; as a consequence, by specifying '127.0.0.1' it forces the function to actually use the port argument: otherwise it merrily ignores it and uses the socket instead.

There are probably other ways to solve the problem! Thought it was worth raising the matter in case anyone else encounters the isssue, or has a better way of resolving it.
Reply
09-13-2020, 06:51 AM, (This post was last modified: 09-13-2020, 09:26 AM by TurboPT.)
#2
RE: Database connection problem
Yes, I've seen a few others (not here, but elsewhere, such as stackoverflow as one example) about the localhost/127.0.0.1 difference with connectivity.

Not sure how/what makes the difference, many have claimed that it works using either one, so there must be configuration aspect somewhere.
Reply
09-13-2020, 07:16 AM,
#3
RE: Database connection problem
From http://pl.php.net/mysql_connect :

"Whenever you specify "localhost" or "localhost:port" as server, the MySQL client library will override this and try to connect to a local socket (named pipe on Windows). If you want to use TCP/IP, use "127.0.0.1" instead of "localhost". If the MySQL client library tries to connect to the wrong local socket, you should set the correct path as in your PHP configuration and leave the server field blank."

My understanding is that localhost and 127.0.0.1 are different. Using localhost the OS will use an internal socket to connect, but the PHP mysqli library will assume you are using the standard port. If you use 127.0.0.1 then you will use TCP/IP sockets as if it were an external server it was connecting to, and you can use any port.

Using localhost is quicker as the internal OS socket will be faster than the TCP/IP ones, but you cannot use it if you want to use a non standard port.

Hope I haven't just confused people more
Tim
Reply
09-13-2020, 09:26 AM,
#4
RE: Database connection problem
That makes sense to me, thanks for the find, Tim.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)